The os module is a built-in Node.js module that returns information about the computer your program runs on, such as the operating system, CPU, memory, user and network interfaces. You load it with import os from 'node:os' and call functions like os.platform(), os.cpus() and os.totalmem(). No installation is needed.
This guide covers the most useful calls of the node os module, what they return, and the details that trip beginners up. Examples target Node.js 22 or 24 LTS.
The node: prefix marks a built-in module and is recommended. In CommonJS you write const os = require('node:os');. The output above is an example; your values depend on your machine.
| Function | Returns | Example |
|---|---|---|
os.platform() | Platform name | 'linux', 'darwin', 'win32' |
os.type() | OS name from the kernel | 'Linux', 'Darwin', 'Windows_NT' |
os.release() | Kernel or OS release | '6.8.0' |
os.version() | Longer version string | build details |
os.arch() | CPU architecture | 'x64', 'arm64' |
os.hostname() | Computer name | 'my-laptop' |
os.uptime() | Seconds since boot | 86400.5 |
Use os.platform() when your code must behave differently per system, for example choosing a command or a path style. Compare against the strings above rather than guessing.
totalmem() and freemem() return bytes, so you convert them yourself. os.cpus() returns an array with one object per logical core, each with model, speed and cumulative times. For deciding how many workers to start, prefer os.availableParallelism() (added in Node.js 18.14), which gives the number of threads the process can use as a hint. Note that on Linux freemem() can look low because the system uses spare memory for caching.
Inside a container, totalmem() may report the host memory, not the container limit, so do not rely on it alone for sizing caches there.
homedir() is the current user's home folder and tmpdir() is the default folder for temporary files. userInfo() returns the username, user id, group id, shell and home directory. Combine these with path.join instead of building paths with string concatenation, so the separators are correct on every system.
os.EOL holds the platform's line ending: '\n' on Linux and macOS, '\r\n' on Windows.
Use it when a file must follow the local convention. For data formats such as JSON or protocols that fix a line ending, write the exact characters instead. os.constants exposes signal numbers and error codes, which you need only in low-level code.
networkInterfaces() returns an object keyed by interface name, each holding addresses with family, address, mac and internal. Filtering out internal removes the loopback address. In older Node versions family was sometimes a number; in current versions compare it to the string 'IPv4' as shown, and test it on your target version.
os.loadavg() returns the 1, 5 and 15 minute load averages. On Windows it always returns zeros, so treat it as Unix-only.
Test os.platform() === 'win32'. The value is 'win32' on both 32-bit and 64-bit Windows.
Use os.availableParallelism() for how many tasks can run in parallel, or os.cpus().length for the count of logical processors the system reports.
Linux uses free memory for disk cache and releases it when programs need it. The value reflects completely unused memory, not what is available to applications.
No. It is a Node.js module and has no browser equivalent.
The os module gives you platform, architecture, memory, CPU, user, directory and network information with simple function calls. Use availableParallelism() for worker counts, os.EOL and os.tmpdir() for portable file work, and remember that memory figures can be misleading in containers and loadavg() is empty on Windows.