Registry / serialization / iso-constants

iso-constants

JSON →
library0.1.2jsnpmunverified

The `iso-constants` package provides Node.js's `process.constants` values in a way that is usable across both Node.js and browser environments. It aims to offer a consistent set of system-level constants, such as `RTLD_LAZY` or `UV_THREADPOOL_SIZE`, regardless of the execution context. Currently at version `0.1.2`, the library maintains a generally low release cadence, primarily issuing patch fixes, indicating a stable and focused scope rather than rapid feature development. A key differentiator is its automatic constant update mechanism, which runs during `npm install` to ensure the most current constants are available. This approach enables developers to write isomorphic code that relies on these specific constants without needing conditional logic for different runtimes, simplifying cross-environment development.

npm install iso-constants
INSTALL
IMPORT
SIG · ISO-CONSTANTS
I
iso-constants
serializationjavascriptv0.1.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

constants
const constants = require('iso-constants');
Primary CommonJS import for the entire constants object.
constants
import constants from 'iso-constants';
import { constants } from 'iso-constants';
Correct ESM import for the default constants object. The package exports a single object, not named properties at the top level.
RTLD_LAZY
import constants from 'iso-constants'; console.log(constants.RTLD_LAZY);
import { RTLD_LAZY } from 'iso-constants';
Individual constants are properties of the main 'constants' object and are not directly exported as named imports from the package root.

Demonstrates how to import and access various Node.js `process.constants`, such as `RTLD_LAZY` and `UV_THREADPOOL_SIZE`, using `iso-constants` in an isomorphic way.

import constants from 'iso-constants'; console.log('--- Node.js System Constants ---'); console.log('RTLD_LAZY:', constants.RTLD_LAZY); console.log('RTLD_NOW:', constants.RTLD_NOW); console.log('UV_THREADPOOL_SIZE:', constants.UV_THREADPOOL_SIZE); // This library ensures these Node.js process.constants are available // in both Node.js and browser environments, providing consistent values. // Example of a constant that might be platform-specific (e.g., Linux only) if (constants.hasOwnProperty('O_DIRECT')) { console.log('O_DIRECT constant is available:', constants.O_DIRECT); } else { console.log('O_DIRECT constant is not available (e.g., non-Linux platform).'); } // Accessing another common constant console.log('F_OK (File exists flag):', constants.F_OK);
Debug
Known issues
gotchaThe package uses a `postinstall` script to fetch and update constants, which can lead to non-deterministic builds if the remote source changes between installs of the same package version. This also requires network access during `npm install`.
fix
Pin exact package versions in your `package.json` and use `npm ci` or `yarn install --frozen-lockfile` to ensure reproducible builds from lock files.
affects: >=0.1.0
breakingAs a `0.1.x` version, the API is not yet considered stable and breaking changes may occur in minor or even patch releases, contrary to semver conventions for `1.0.0`+ versions.
fix
Review changelogs carefully for each update and test thoroughly, especially when upgrading between minor versions.
affects: <1.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use CommonJS `require` syntax in an ESM module context (e.g., in a `.mjs` file or a file within a package with `"type": "module"` in `package.json`).
fix
Change the import statement to `import constants from 'iso-constants';` in ESM files, or ensure your file is treated as CommonJS (e.g., by using `.cjs` extension or configuring `"type": "commonjs"` in your `package.json`).
TypeError: Cannot read properties of undefined (reading 'RTLD_LAZY') or similar 'constants' is undefined
The `constants` object was not successfully imported or initialized. This can happen if the `postinstall` script, which fetches the actual constant values, failed during `npm install`.
fix
Verify `iso-constants` is correctly installed by running `npm reinstall iso-constants` to re-execute the `postinstall` script. Check for any network errors or permission issues during the installation process.
Upgrade
Version history
0.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
2
Resources
iso-constants — npm install iso-constants · libregistry