Node.js os - CPU count, memory, platform, home and temp directories
Answer: Use os.totalmem() for system memory, os.platform() for the platform, and os.homedir() and os.tmpdir() for directories. The node:os module provides operating system-related utility methods and properties.
Examples
import os from 'node:os';
const workers = os.availableParallelism(); // size a worker pool
const freeMiB = Math.round(os.freemem() / 2 ** 20);
const totalMiB = Math.round(os.totalmem() / 2 ** 20);
os.platform(); // 'linux', 'darwin', 'win32', ...
os.arch(); // 'x64', 'arm64', ...
os.type(); // 'Linux', 'Darwin', 'Windows_NT'
os.hostname();
os.homedir(); // uses $HOME on POSIX
os.tmpdir(); // no trailing slash
os.loadavg(); // [1, 5, 15] minute averages
const lines = ['a', 'b'].join(os.EOL); // \n or \r\n
Functions
| Function | Returns | |---|---| | os.availableParallelism() | an estimate of the default amount of parallelism a program should use; always greater than zero | | os.cpus() | an array of objects with information about each logical CPU core; can be empty | | os.freemem() / os.totalmem() | free and total system memory in bytes | | os.platform() | the operating system platform the Node.js binary was compiled for | | os.arch() | the CPU architecture the Node.js binary was compiled for | | os.homedir() | the current user's home directory path | | os.tmpdir() | the operating system's default directory for temporary files | | os.loadavg() | the 1, 5, and 15 minute load averages | | os.networkInterfaces() | network interfaces that have been assigned a network address |
Rules
os.EOLis the operating system-specific end-of-line marker:\non POSIX and\r\non Windows.- The
os.cpus()array will be empty if no CPU information is available, such as when /proc is unavailable. os.platform()is equivalent toprocess.platform, andos.arch()toprocess.arch.- On POSIX,
os.homedir()uses the $HOME environment variable if defined.
See also
Claims
- id: C1 claim: os provides OS-related utilities. source: S1 evidence: "The node:os module provides operating system-related utility methods and properties."
- id: C2 claim: cpus can return an empty array. source: S1 evidence: "The array will be empty if no CPU information is available"
- id: C3 claim: availableParallelism estimates parallelism. source: S2 evidence: "Returns an estimate of the default amount of parallelism a program should use."
Sources
- [S1] OS. Node.js API docs. https://nodejs.org/api/os.html . License: MIT. Accessed 2026-11-18.
- [S2] doc/api/os.md. nodejs/node (GitHub). https://github.com/nodejs/node/blob/main/doc/api/os.md . License: MIT. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Node.js API docs, OS; nodejs/node (GitHub), doc/api/os.md. MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Node.js API docs, OS; nodejs/node (GitHub), doc/api/os.md. MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors.
Cite this
iinventedlight. 2026. "Node.js os - CPU count, memory, platform, home and temp directories." iinventedlight Library, iil:note:stg2c0mq, version of 2026-11-18. https://iinventedlight.com/library/notes/node-os/. License: CC-BY-4.0.
@misc{iil_note_stg2c0mq,
author = {{iinventedlight}},
title = {{Node.js os - CPU count, memory, platform, home and temp directories}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/node-os/},
note = {Permanent ID iil:note:stg2c0mq. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- node-os.table.json (table; CC-BY-4.0)
- node-os.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/node-os.md.