node-sysconf
v5.0.0
Published
Get configurable system variables.
Readme
sysconf For Node.js
Get configurable system variables.
Requirements and Installation
Linux or macOS, Node.js 24 or later and Rust 1.88 or later are required. Install Rust with rustup and a C compiler for the native linker.
npm install node-sysconfInstallation compiles the native module from source using the included Cargo.lock. There are no prebuilt platform packages. Package managers that block dependency build scripts must allow the node-sysconf install script; for pnpm, approve node-sysconf with pnpm approve-builds and rebuild it with pnpm rebuild node-sysconf. If npm requires script approval, use npm install-scripts approve node-sysconf followed by npm rebuild node-sysconf.
Usage
You can use sysconf function to get the value of system variables.
import { _SC_NPROCESSORS_ONLN, _SC_PAGE_SIZE, sysconf } from "node-sysconf";
console.log(sysconf(_SC_PAGE_SIZE)); // 4096
console.log(sysconf(_SC_NPROCESSORS_ONLN)); // 8The _SC_* constants from POSIX are exported, along with _SC_PHYS_PAGES, _SC_AVPHYS_PAGES, _SC_NPROCESSORS_CONF and _SC_NPROCESSORS_ONLN. Their values depend on the platform.
Return Value
Like the C function, sysconf returns -1 when
- the name is not valid on the current platform,
- the variable has no definite limit, or
- the option is not supported.
A name that is not an integer is treated as an invalid name, so sysconf(1.5) also returns -1.
Some constants are not defined by macOS, such as _SC_AVPHYS_PAGES, _SC_THREAD_ROBUST_PRIO_INHERIT, _SC_THREAD_ROBUST_PRIO_PROTECT and _SC_V7_*. They are still exported on macOS so the same imports work on every platform, but their value is -1 and sysconf always returns -1 for them.
