node:os
Node-compatible operating system metadata utilities.
Available in both vjs and vjs-lite runtimes. Enabled by default unless
--no-node-compat is passed.
import ... from "node:os"
node-compat (enabled by default; disable with --no-node-compat)Example
Section titled “Example”import { arch, cpus, homedir, hostname, platform, tmpdir } from "node:os";
console.log(platform(), arch(), cpus().length);console.log(hostname(), homedir(), tmpdir());platformv0.0.0-alpha.0archv0.0.0-alpha.0homedirv0.0.0-alpha.0tmpdirv0.0.0-alpha.0hostnamev0.0.0-alpha.0cpusv0.0.0-alpha.0endiannessv0.0.0-alpha.0"BE" or "LE").typev0.0.0-alpha.0machinev0.0.0-alpha.0availableParallelismv0.0.0-alpha.2releasev0.0.0-alpha.2Functions
Section titled “Functions”platform
Section titled “platform”export function platform(): string;
Return the operating system platform identifier.
string — Node-compatible platform string such as "linux", "darwin", or "win32".import { platform } from "node:os";
console.log(platform());export function arch(): string;
Return the operating system CPU architecture identifier.
string — Node-compatible architecture string such as "x64" or "arm64".import { arch } from "node:os";
console.log(arch());homedir
Section titled “homedir”export function homedir(): string;
Return the current user’s home directory path.
string — Path string of the current user's home directory.Error— withcode = "ERR_UNAVAILABLE"or"EINVAL"if the home directory cannot be determined or is not valid UTF-8.
import { homedir } from "node:os";
console.log(homedir());tmpdir
Section titled “tmpdir”export function tmpdir(): string;
Return the operating system’s default directory for temporary files.
string — Path string of the system temporary directory.Error— withcode = "EINVAL"if the temporary directory path is not valid UTF-8.
import { tmpdir } from "node:os";
console.log(tmpdir());hostname
Section titled “hostname”export function hostname(): string;
Return the host name of the operating system.
string — Hostname string of the machine.Error— withcode = "ERR_UNAVAILABLE"or"EINVAL"if querying the hostname fails or returns invalid UTF-8.
import { hostname } from "node:os";
console.log(hostname());export function cpus(): CpuInfo[];
Return an array of objects containing information about each logical CPU core.
CpuInfo[] — Array of CpuInfo descriptors matching the host logical CPU count.import { cpus } from "node:os";
console.log(`Logical cores: ${cpus().length}`);endianness
Section titled “endianness”export function endianness(): "BE" | "LE";
Return the CPU endianness ("BE" or "LE").
"BE" | "LE" — "BE" for big-endian or "LE" for little-endian architectures.import { endianness } from "node:os";
console.log(endianness());export function type(): string;
Return the operating system name.
string — OS name such as "Linux", "Darwin", or "Windows_NT".import { type } from "node:os";
console.log(type());machine
Section titled “machine”export function machine(): string;
Return the machine type string.
string — Machine hardware identifier such as "x86_64" or "arm64".import { machine } from "node:os";
console.log(machine());availableParallelism
Section titled “availableParallelism”export function availableParallelism(): number;
Return an estimate of the default amount of parallelism a program should use.
number — Positive integer count of available parallel execution units.release
Section titled “release”export function release(): string;
Return the operating system release string.
string — OS release version string (for example "6.8.0" or "23.4.0").Interfaces
Section titled “Interfaces”CpuInfo
Section titled “CpuInfo”export interface CpuInfo {
model: string;
speed: number;
times: {
/**
* Milliseconds spent in user mode.
*
* @since 0.0.0-alpha.0
*/
user: number;
/**
* Milliseconds spent in nice mode.
*
* @since 0.0.0-alpha.0
*/
nice: number;
/**
* Milliseconds spent in system (kernel) mode.
*
* @since 0.0.0-alpha.0
*/
sys: number;
/**
* Milliseconds spent in idle mode.
*
* @since 0.0.0-alpha.0
*/
idle: number;
/**
* Milliseconds spent servicing hardware interrupts.
*
* @since 0.0.0-alpha.0
*/
irq: number;
};
}
CPU core descriptor returned in the array from cpus().
| Property | Type | Description | Since |
|---|---|---|---|
model | string | CPU model string (currently "unknown" in vaeljs). | v0.0.0-alpha.0 |
speed | number | CPU clock speed in MHz (currently 0 in vaeljs). | v0.0.0-alpha.0 |
times | {
/**
* Milliseconds spent in user mode.
*
* @since 0.0.0-alpha.0
*/
user: number;
/**
* Milliseconds spent in nice mode.
*
* @since 0.0.0-alpha.0
*/
nice: number;
/**
* Milliseconds spent in system (kernel) mode.
*
* @since 0.0.0-alpha.0
*/
sys: number;
/**
* Milliseconds spent in idle mode.
*
* @since 0.0.0-alpha.0
*/
idle: number;
/**
* Milliseconds spent servicing hardware interrupts.
*
* @since 0.0.0-alpha.0
*/
irq: number;
} | Cumulative CPU time breakdown in milliseconds (zero-initialized in vaeljs). | v0.0.0-alpha.0 |
OsConstants
Section titled “OsConstants”export interface OsConstants {
readonly signals: Readonly<Record<string, number>>;
readonly errno: Readonly<Record<string, number>>;
readonly priority: Readonly<Record<string, number>>;
readonly dlopen: Readonly<Record<string, number>>;
readonly UV_UDP_REUSEADDR: number;
}
Operating system constants exposed on os.constants.
| Property | Type | Description | Since |
|---|---|---|---|
signals readonly | Readonly<Record<string, number>> | POSIX/platform signal numbers (SIGINT, SIGTERM, etc.). | v0.0.0-alpha.2 |
errno readonly | Readonly<Record<string, number>> | POSIX/platform errno error codes (ENOENT, EACCES, etc.). | v0.0.0-alpha.2 |
priority readonly | Readonly<Record<string, number>> | Process scheduling priority constants (PRIORITY_LOW, PRIORITY_NORMAL, etc.). | v0.0.0-alpha.2 |
dlopen readonly | Readonly<Record<string, number>> | Dynamic linker flags (RTLD_LAZY, RTLD_NOW, etc.). | v0.0.0-alpha.2 |
UV_UDP_REUSEADDR readonly | number | Socket address reuse constant (UV_UDP_REUSEADDR). | v0.0.0-alpha.2 |
Constants
Section titled “Constants”export const EOL: "\n" | "\r\n";
Operating system end-of-line marker ("\n" or "\r\n").
devNull
Section titled “devNull”export const devNull: "/dev/null" | "\\\\.\\nul";
Platform-specific path to the null device ("/dev/null" on POSIX, "\\\\.\\nul" on Windows).
constants
Section titled “constants”export const constants: OsConstants;
Operating system signal, errno, priority, and dlopen constants.
Default Export
Section titled “Default Export”default export
Section titled “default export”const _default: {
/** Return the operating system platform identifier. @since 0.0.0-alpha.0 */
platform: typeof platform;
/** Return the operating system CPU architecture identifier. @since 0.0.0-alpha.0 */
arch: typeof arch;
/** Operating system end-of-line marker (`"\n"` or `"\r\n"`). @since 0.0.0-alpha.0 */
EOL: typeof EOL;
/** Return the current user's home directory path. @since 0.0.0-alpha.0 */
homedir: typeof homedir;
/** Return the system temporary directory path. @since 0.0.0-alpha.0 */
tmpdir: typeof tmpdir;
/** Return the operating system host name. @since 0.0.0-alpha.0 */
hostname: typeof hostname;
/** Return an array of logical CPU core descriptors. @since 0.0.0-alpha.0 */
cpus: typeof cpus;
/** Return the CPU endianness (`"BE"` or `"LE"`). @since 0.0.0-alpha.0 */
endianness: typeof endianness;
/** Return the operating system name. @since 0.0.0-alpha.0 */
type: typeof type;
/** Return the machine hardware type string. @since 0.0.0-alpha.0 */
machine: typeof machine;
/** Return estimated default parallelism count. @since 0.0.0-alpha.2 */
availableParallelism: typeof availableParallelism;
/** Return the operating system release string. @since 0.0.0-alpha.2 */
release: typeof release;
/** Platform-specific path to the null device. @since 0.0.0-alpha.2 */
readonly devNull: typeof devNull;
/** Operating system constants. @since 0.0.0-alpha.2 */
readonly constants: OsConstants;
};
export default _default;
Default export object providing all node:os functions and EOL.
