Node.js Operating System Module

Prepare for Node.js interviews and strengthen your backend development skills with this comprehensive flashcard set focused on the Node.js OS module. Designed for developers ranging from intermediate to senior levels, this collection covers both theoretical concepts and practical applications commonly encountered in production systems. The set explores essential OS module APIs, including system architecture detection, CPU information retrieval, memory monitoring, process scheduling, operating system identification, network interface inspection, uptime tracking, temporary directory management, and user environment information. You'll also learn how to work with operating system constants, error codes, signals, scheduling priorities, platform-specific behaviors, and libuv integrations. Topics include os.arch(), os.platform(), os.type(), os.release(), os.version(), os.cpus(), os.availableParallelism(), os.totalmem(), os.freemem(), os.loadavg(), os.networkInterfaces(), os.hostname(), os.homedir(), os.tmpdir(), os.userInfo(), os.endianness(), os.machine(), os.uptime(), process priorities, signal handling, POSIX error codes, Windows-specific errors, and dlopen constants. Beyond API knowledge, the cards emphasize real-world scenarios such as building monitoring tools, collecting server diagnostics, optimizing containerized applications, implementing health checks, capacity planning, performance analysis, environment detection, and cross-platform application development. Whether you are preparing for technical interviews, reviewing Node.js fundamentals, onboarding new team members, or improving your understanding of operating system interactions in JavaScript applications, this flashcard set provides a structured and efficient learning path. Ideal for Node.js developers, backend engineers, full-stack developers, technical leads, and software architects seeking deeper knowledge of system-level programming concepts within the Node.js ecosystem. You may also be interested in: Master Node.js: From Basics to Production Node.js Stream Module Node.js Cluster Module Node.js Child Process Module Node.js Buffer API Interview Questions Node.js Crypto Module Node.js File System Module

Проверка знаний

Пройдите тест перед обучением, чтобы увидеть знакомые темы и найти пробелы.

Пройти тест

Уроки в мессенджере

Изучайте карточки и возвращайтесь к пройденному в интерактивных уроках.

Как проходят уроки

Интервальное повторение

Получайте отдельные карточки для повторения через интервалы, которые помогают дольше помнить материал.

Как работает повторение
OS

The node:os module offers information about the operating system, CPU, memory, user, network interfaces, and process-related constants. Import it with import os from "node:os" in an ES module or require("node:os") in CommonJS. Its methods query the current system; results can differ between operating systems and machines.

1/32
os.EOL

os.EOL is a string containing the platform’s line-ending marker. It is "\n" on POSIX systems and "\r\n" on Windows. Use it when generating platform-native text lines; it is a property, so read os.EOL without parentheses. It does not inspect an existing file to discover that file’s line endings.

2/32
os.availableParallelism()

This function is a small wrapper about libuv's uv_available_parallelism().

3/32
os.arch()

os.arch() returns the CPU architecture for which the Node.js binary was compiled, as a string. It is equivalent to process.arch. Examples of current values include "arm64", "ia32", and "x64". It does not report the operating-system platform; use os.platform() for that. The result reflects the Node.js binary target, which may differ from the physical host architecture.

4/32
os.constants

os.constants is an object of operating-system-related constants. It groups process signals under os.constants.signals, error numbers under os.constants.errno, and scheduling priorities under os.constants.priority. Other groups include dlopen and libuv constants. Availability varies by operating system, so code should not assume every constant exists everywhere.

5/32
os.cpus()

Returns an array of objects containing information about each logical CPU core.

6/32
os.devNull

os.devNull is a string containing the path of the platform’s null device. It is "/dev/null" on POSIX and "\\.\nul" on Windows. Writing to the null device discards data; reading it provides no data. Use this property instead of hard-coding one platform’s path when redirecting output to a null sink.

7/32
os.endianness()
Returns: <string> Returns a string identifying the endianness of the CPU for which the Node.js binary was compiled. Possible values are 'BE' for big endian and 'LE' for little endian.
8/32
os.freemem()

os.freemem() returns free system memory as an integer number of bytes. It describes the machine, not just the current Node.js process. Compare it with os.totalmem() when you need a rough free-to-total ratio; the reading can change as other programs use memory. The expression os.totalmem() - os.freemem() gives an approximate amount of memory that is not free.

9/32
os.getPriority([pid])

Returns the scheduling priority for the process specified by pid.


If pid is not provided or is 0, the priority of the current process is returned.

10/32
os.homedir()
Returns: <string> Returns the string path of the current user's home directory. On POSIX, it uses the $HOME environment variable if defined. Otherwise it uses the effective UID to look up the user's home directory.
11/32
os.hostname()

os.hostname() returns the operating system’s host name as a string. It identifies the current host, whereas os.homedir() returns a path to the current user’s home directory. Call os.hostname() without arguments; the returned name depends on the machine’s configuration and can change if the host is renamed.

12/32
os.loadavg()
Returns: <number[]> Returns an array containing the 1, 5, and 15 minute load averages. The load average is a measure of system activity calculated by the operating system and expressed as a fractional number.
13/32
os.machine()
Returns: <string> Returns the machine type as a string, such as arm, arm64, aarch64, mips, mips64, ppc64, ppc64le, s390, s390x, i386, i686, x86_64.
14/32
os.networkInterfaces()
Returns: <Object> Returns an object containing network interfaces that have been assigned a network address. Each key on the returned object identifies a network interface. The associated value is an array of objects that each describe an assigned network address. eslint-skip
15/32
os.platform()
Returns: <string> Returns a string identifying the operating system platform for which the Node.js binary was compiled. The value is set at compile time. Possible values are 'aix', 'darwin', 'freebsd','linux', 'openbsd', 'sunos', and 'win32'.
16/32
os.release()

os.release() returns the operating-system release version as a string. It is different from os.type(), which identifies the operating-system name, and from os.version(), which identifies the kernel version. On POSIX, Node.js obtains the release through uname(3); on Windows it uses a Windows version API. Use the result for display or diagnostics rather than assuming it has the same format on every platform.

17/32
os.setPriority([pid, ]priority)
pid <integer> The process ID to set scheduling priority for. Default: 0. priority <integer> The scheduling priority to assign to the process.
18/32
os.tmpdir()
Returns: <string> Returns the operating system's default directory for temporary files as a string.
19/32
os.totalmem()

os.totalmem() returns total system memory as an integer number of bytes. It describes machine memory rather than the memory used by the Node.js process. Compare it with os.freemem() to estimate the currently free share; divide the byte value by 1024 squared for an approximate MiB value. The total and free values answer different questions.

20/32
os.type()
Returns: <string> Returns the operating system name as returned by uname(3). For example, it returns 'Linux' on Linux, 'Darwin' on macOS, and 'Windows_NT' on Windows.
21/32
os.uptime()

os.uptime() returns system uptime as an integer number of seconds since the operating system started. It is different from process.uptime(), which measures how long the current Node.js process has run. Divide by 60 for an approximate number of minutes, or by 3600 for hours. A system restart resets this measurement.

22/32
os.userInfo([options])
options <Object> encoding <string> Character encoding used to interpret resulting strings. If encoding is set to 'buffer', the username, shell, and homedir values will be Buffer instances. Default: 'utf8'.
23/32
os.version()
Returns: <string> Returns a string identifying the kernel version.
24/32
OS constants

os.constants contains groups of operating-system-related constants. Common groups include signals for process signals, errno for error codes, priority for scheduling levels, and dlopen for library loading flags. Some groups or entries are platform-specific. Inspect the relevant group before relying on a constant across operating systems.

25/32
Signal constants
History Version Changes v5.11.0 Added support for SIGINFO. The following signal constants are exported by os.constants.signals. Constant Description
26/32
Error constants

os.constants.errno groups named operating-system error constants. For example, EACCES means insufficient permission, ENOENT means a missing file or directory, and EADDRINUSE means a network address is already in use. Names are easier to understand than raw numeric values. The exact constants available and their numeric values can vary by platform.

27/32
POSIX error constants
Constant Description
28/32
Windows-specific error constants
The following error codes are specific to the Windows operating system. Constant Description
29/32
dlopen constants
If available on the operating system, the following constants are exported in os.constants.dlopen. See dlopen(3) for detailed information. Constant Description
30/32
Priority constants
The following process scheduling constants are exported by os.constants.priority. Constant Description
31/32
libuv constants

The libuv constants group is exposed through os.constants.libuv. The Node.js OS reference lists UV_UDP_REUSEADDR, a flag connected to reuse of a UDP socket address. libuv uses it when binding UDP handles; address reuse behavior can vary by platform. This is a low-level constant, so ordinary Node.js UDP applications usually use the node:dgram reuseAddr option instead.

32/32