SOLFIND
Web Lens
Portal home

OS | Node.js v22.23.2 Documentation

https://nodejs.org/docs/latest-v22.x/api/os.html • 75 KB fetched
Open original page


OS | Node.js v22.23.2 Documentation Skip to content Node.js * About this documentation * Usage and example * Assertion testing * Asynchronous context tracking * Async hooks * Buffer * C++ addons * C/C++ addons with Node-API * C++ embedder API * Child processes * Cluster * Command-line options * Console * Crypto * Debugger * Deprecated APIs * Diagnostics Channel * DNS * Domain * Environment Variables * Errors * Events * File system * Globals * HTTP * HTTP/2 * HTTPS * Inspector * Internationalization * Modules: CommonJS modules * Modules: ECMAScript modules * Modules: node:module API * Modules: Packages * Modules: TypeScript * Net * OS * Path * Performance hooks * Permissions * Process * Punycode * Query strings * Readline * REPL * Report * Single executable applications * SQLite * Stream * String decoder * Test runner * Timers * TLS/SSL * Trace events * TTY * UDP/datagram * URL * Utilities * V8 * VM * WASI * Web Crypto API * Web Streams API * Worker threads * Zlib * Code repository and issue tracker Node.js v22.23.2 documentation * Node.js v22.23.2 * Table of contents * OS * os.EOL * os.availableParallelism() * os.arch() * os.constants * os.cpus() * os.devNull * os.endianness() * os.freemem() * os.getPriority([pid]) * os.homedir() * os.hostname() * os.loadavg() * os.machine() * os.networkInterfaces() * os.platform() * os.release() * os.setPriority([pid, ]priority) * os.tmpdir() * os.totalmem() * os.type() * os.uptime() * os.userInfo([options]) * os.version() * OS constants * Signal constants * Error constants * POSIX error constants * Windows-specific error constants * dlopen constants * Priority constants * libuv constants * Index * About this documentation * Usage and example * Index * Assertion testing * Asynchronous context tracking * Async hooks * Buffer * C++ addons * C/C++ addons with Node-API * C++ embedder API * Child processes * Cluster * Command-line options * Console * Crypto * Debugger * Deprecated APIs * Diagnostics Channel * DNS * Domain * Environment Variables * Errors * Events * File system * Globals * HTTP * HTTP/2 * HTTPS * Inspector * Internationalization * Modules: CommonJS modules * Modules: ECMAScript modules * Modules: node:module API * Modules: Packages * Modules: TypeScript * Net * OS * Path * Performance hooks * Permissions * Process * Punycode * Query strings * Readline * REPL * Report * Single executable applications * SQLite * Stream * String decoder * Test runner * Timers * TLS/SSL * Trace events * TTY * UDP/datagram * URL * Utilities * V8 * VM * WASI * Web Crypto API * Web Streams API * Worker threads * Zlib * Code repository and issue tracker * Other versions * 26.x * 25.x * 24.x LTS * 23.x * 22.x LTS * 21.x * 20.x * 19.x * 18.x * 17.x * 16.x * 15.x * 14.x * 13.x * 12.x * 11.x * 10.x * 9.x * 8.x * 7.x * 6.x * 5.x * 4.x * 0.12.x * 0.10.x * Options * View on single page * View as JSON * Edit on GitHub Table of contents * OS * os.EOL * os.availableParallelism() * os.arch() * os.constants * os.cpus() * os.devNull * os.endianness() * os.freemem() * os.getPriority([pid]) * os.homedir() * os.hostname() * os.loadavg() * os.machine() * os.networkInterfaces() * os.platform() * os.release() * os.setPriority([pid, ]priority) * os.tmpdir() * os.totalmem() * os.type() * os.uptime() * os.userInfo([options]) * os.version() * OS constants * Signal constants * Error constants * POSIX error constants * Windows-specific error constants * dlopen constants * Priority constants * libuv constants OS # Stability: 2 - Stable Source Code: lib/os.js The node:os module provides operating system-related utility methods and properties. It can be accessed using: import os from 'node:os' ; const os = require ( 'node:os' ); copy os.EOL # Added in: v0.7.8 * Type: <string> The operating system-specific end-of-line marker. * \n on POSIX * \r\n on Windows os.availableParallelism() # Added in: v19.4.0, v18.14.0 * Returns: <integer> Returns an estimate of the default amount of parallelism a program should use. Always returns a value greater than zero. This function is a small wrapper about libuv's uv_available_parallelism() . os.arch() # Added in: v0.5.0 * Returns: <string> Returns the operating system CPU architecture for which the Node.js binary was compiled. Possible values are 'arm' , 'arm64' , 'ia32' , 'loong64' , 'mips' , 'mipsel' , 'ppc' , 'ppc64' , 'riscv64' , 's390' , 's390x' , and 'x64' . The return value is equivalent to process.arch . os.constants # Added in: v6.3.0 * Type: <Object> Contains commonly used operating system-specific constants for error codes, process signals, and so on. The specific constants defined are described in OS constants . os.cpus() # Added in: v0.3.3 * Returns: <Object[]> Returns an array of objects containing information about each logical CPU core. The array will be empty if no CPU information is available, such as if the /proc file system is unavailable. The properties included on each object include: * model <string> * speed <number> (in MHz) * times <Object> * user <number> The number of milliseconds the CPU has spent in user mode. * nice <number> The number of milliseconds the CPU has spent in nice mode. * sys <number> The number of milliseconds the CPU has spent in sys mode. * idle <number> The number of milliseconds the CPU has spent in idle mode. * irq <number> The number of milliseconds the CPU has spent in irq mode. [ { model : 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz' , speed : 2926 , times : { user : 252020 , nice : 0 , sys : 30340 , idle : 1070356870 , irq : 0 , }, }, { model : 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz' , speed : 2926 , times : { user : 306960 , nice : 0 , sys : 26980 , idle : 1071569080 , irq : 0 , }, }, { model : 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz' , speed : 2926 , times : { user : 248450 , nice : 0 , sys : 21750 , idle : 1070919370 , irq : 0 , }, }, { model : 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz' , speed : 2926 , times : { user : 256880 , nice : 0 , sys : 19430 , idle : 1070905480 , irq : 20 , }, }, ] copy nice values are POSIX-only. On Windows, the nice values of all processors are always 0. os.cpus().length should not be used to calculate the amount of parallelism available to an application. Use os.availableParallelism() for this purpose. os.devNull # Added in: v16.3.0, v14.18.0 * Type: <string> The platform-specific file path of the null device. * \\.\nul on Windows * /dev/null on POSIX os.endianness() # Added in: v0.9.4 * 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. os.freemem() # Added in: v0.3.3 * Returns: <integer> Returns the amount of free system memory in bytes as an integer. os.getPriority([pid]) # Added in: v10.10.0 * pid <integer> The process ID to retrieve scheduling priority for. Default: 0 . * Returns: <integer> 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. os.homedir() # Added in: v2.3.0 * 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. On Windows, it uses the USERPROFILE environment variable if defined. Otherwise it uses the path to the profile directory of the current user. os.hostname() # Added in: v0.3.3 * Returns: <string> Returns the host name of the operating system as a string. os.loadavg() # Added in: v0.3.3 * 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. The load average is a Unix-specific concept. On Windows, the return value is always [0, 0, 0] . os.machine() # Added in: v18.9.0, v16.18.0 * Returns: <string> Returns the machine type as a string, such as arm , arm64 , aarch64 , mips , mips64 , ppc64 , ppc64le , s390 , s390x , i386 , i686 , x86_64 . On POSIX systems, the machine type is determined by calling uname(3) . On Windows, RtlGetVersion() is used, and if it is not available, GetVersionExW() will be used. See https://en.wikipedia.org/wiki/Uname#Examples for more information. os.networkInterfaces() # History Version Changes v18.4.0 The family property now returns a string instead of a number. v18.0.0 The family property now returns a number instead of a string. v0.6.0 Added in: v0.6.0 * 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. The properties available on the assigned network address object include: * address <string> The assigned IPv4 or IPv6 address * netmask <string> The IPv4 or IPv6 network mask * family <string> Either IPv4 or IPv6 * mac <string> The MAC address of the network interface * internal <boolean> true if the network interface is a loopback or similar interface that is not remotely accessible; otherwise false * scopeid <number> The numeric IPv6 scope ID (only specified when family is IPv6 ) * cidr <string> The assigned IPv4 or IPv6 address with the routing prefix in CIDR notation. If the netmask is invalid, this property is set to null . { lo : [ { address : '127.0.0.1' , netmask : '255.0.0.0' , family : 'IPv4' , mac : '00:00:00:00:00:00' , internal : true , cidr : '127.0.0.1/8' }, { address : '::1' , netmask : 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' , family : 'IPv6' , mac : '00:00:00:00:00:00' , scopeid : 0 , internal : true , cidr : '::1/128' } ], eth0 : [ { address : '192.168.1.108' , netmask : '255.255.255.0' , family : 'IPv4' , mac : '01:02:03:0a:0b:0c' , internal : false , cidr : '192.168.1.108/24' }, { address : 'fe80::a00:27ff:fe4e:66a1' , netmask : 'ffff:ffff:ffff:ffff::' , family : 'IPv6' , mac : '01:02:03:0a:0b:0c' , scopeid : 1 , internal : false , cidr : 'fe80::a00:27ff:fe4e:66a1/64' } ] } copy os.platform() # Added in: v0.5.0 * 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' . The return value is equivalent to process.platform . The value 'android' may also be returned if Node.js is built on the Android operating system. Android support is experimental . os.release() # Added in: v0.3.3 * Returns: <string> Returns the operating system as a string. On POSIX systems, the operating system release is determined by calling uname(3) . On Windows, GetVersionExW() is used. See https://en.wikipedia.org/wiki/Uname#Examples for more information. os.setPriority([pid, ]priority) # Added in: v10.10.0 * pid <integer> The process ID to set scheduling priority for. Default: 0 . * priority <integer> The scheduling priority to assign to the process. Attempts to set the scheduling priority for the process specified by pid . If pid is not provided or is 0 , the process ID of the current process is used. The priority input must be an integer between -20 (high priority) and 19 (low priority). Due to differences between Unix priority levels and Windows priority classes, priority is mapped to one of six priority constants in os.constants.priority . When retrieving a process priority level, this range mapping may cause the return value to be slightly different on Windows. To avoid confusion, set priority to one of the priority constants. On Windows, setting priority to PRIORITY_HIGHEST requires elevated user privileges. Otherwise the set priority will be silently reduced to PRIORITY_HIGH . os.tmpdir() # History Version Changes v2.0.0 This function is now cross-platform consistent and no longer returns a path with a trailing slash on any platform. v0.9.9 Added in: v0.9.9 * Returns: <string> Returns the operating system's default directory for temporary files as a string. On Windows, the result can be overridden by TEMP and TMP environment variables, and TEMP takes precedence over TMP . If neither is set, it defaults to %SystemRoot%\temp or %windir%\temp . On non-Windows platforms, TMPDIR , TMP and TEMP environment variables will be checked to override the result of this method, in the described order. If none of them is set, it defaults to /tmp . Some operating system distributions would either configure TMPDIR (non-Windows) or TEMP and TMP (Windows) by default without additional configurations by the system administrators. The result of os.tmpdir() typically reflects the system preference unless it's explicitly overridden by the users. os.totalmem() # Added in: v0.3.3 * Returns: <integer> Returns the total amount of system memory in bytes as an integer. os.type() # Added in: v0.3.3 * 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. See https://en.wikipedia.org/wiki/Uname#Examples for additional information about the output of running uname(3) on various operating systems. os.uptime() # History Version Changes v10.0.0 The result of this function no longer contains a fraction component on Windows. v0.3.3 Added in: v0.3.3 * Returns: <integer> Returns the system uptime in number of seconds. os.userInfo([options]) # Added in: v6.0.0 * 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' . * Returns: <Object> Returns information about the currently effective user. On POSIX platforms, this is typically a subset of the password file. The returned object includes the username , uid , gid , shell , and homedir . On Windows, the uid and gid fields are -1 , and shell is null . The value of homedir returned by os.userInfo() is provided by the operating system. This differs from the result of os.homedir() , which queries environment variables for the home directory before falling back to the operating system response. Throws a SystemError if a user has no username or homedir . os.version() # Added in: v13.11.0, v12.17.0 * Returns: <string> Returns a string identifying the kernel version. On POSIX systems, the operating system release is determined by calling uname(3) . On Windows, RtlGetVersion() is used, and if it is not available, GetVersionExW() will be used. See https://en.wikipedia.org/wiki/Uname#Examples for more information. OS constants # The following constants are exported by os.constants . Not all constants will be available on every operating system. Signal constants # History Version Changes v5.11.0 Added support for SIGINFO . The following signal constants are exported by os.constants.signals . Constant Description SIGHUP Sent to indicate when a controlling terminal is closed or a parent process exits. SIGINT Sent to indicate when a user wishes to interrupt a process ( Ctrl + C ). SIGQUIT Sent to indicate when a user wishes to terminate a process and perform a core dump. SIGILL Sent to a process to notify that it has attempted to perform an illegal, malformed, unknown, or privileged instruction. SIGTRAP Sent to a process when an exception has occurred. SIGABRT Sent to a process to request that it abort. SIGIOT Synonym for SIGABRT SIGBUS Sent to a process to notify that it has caused a bus error. SIGFPE Sent to a process to notify that it has performed an illegal arithmetic operation. SIGKILL Sent to a process to terminate it immediately. SIGUSR1 SIGUSR2 Sent to a process to identify user-defined conditions. SIGSEGV Sent to a process to notify of a segmentation fault. SIGPIPE Sent to a process when it has attempted to write to a disconnected pipe. SIGALRM Sent to a process when a system timer elapses. SIGTERM Sent to a process to request termination. SIGCHLD Sent to a process when a child process terminates. SIGSTKFLT Sent to a process to indicate a stack fault on a coprocessor. SIGCONT Sent to instruct the operating system to continue a paused process. SIGSTOP Sent to instruct the operating system to halt a process. SIGTSTP Sent to a process to request it to stop. SIGBREAK Sent to indicate when a user wishes to interrupt a process. SIGTTIN Sent to a process when it reads from the TTY while in the background. SIGTTOU Sent to a process when it writes to the TTY while in the background. SIGURG Sent to a process when a socket has urgent data to read. SIGXCPU Sent to a process when it has exceeded its limit on CPU usage. SIGXFSZ Sent to a process when it grows a file larger than the maximum allowed. SIGVTALRM Sent to a process when a virtual timer has elapsed. SIGPROF Sent to a process when a system timer has elapsed. SIGWINCH Sent to a process when the controlling terminal has changed its size. SIGIO Sent to a process when I/O is available. SIGPOLL Synonym for SIGIO SIGLOST Sent to a process when a file lock has been lost. SIGPWR Sent to a process to notify of a power failure. SIGINFO Synonym for SIGPWR SIGSYS Sent to a process to notify of a bad argument. SIGUNUSED Synonym for SIGSYS Error constants # The following error constants are exported by os.constants.errno . POSIX error constants # Constant Description E2BIG Indicates that the list of arguments is longer than expected. EACCES Indicates that the operation did not have sufficient permissions. EADDRINUSE Indica

Links found on this page

  1. Skip to content [direct]
  2. Node.js [direct]
  3. About this documentation [direct]
  4. Usage and example [direct]
  5. Assertion testing [direct]
  6. Asynchronous context tracking [direct]
  7. Async hooks [direct]
  8. Buffer [direct]
  9. C++ addons [direct]
  10. C/C++ addons with Node-API [direct]
  11. C++ embedder API [direct]
  12. Child processes [direct]
  13. Cluster [direct]
  14. Command-line options [direct]
  15. Console [direct]
  16. Crypto [direct]
  17. Debugger [direct]
  18. Deprecated APIs [direct]
  19. Diagnostics Channel [direct]
  20. DNS [direct]
  21. Domain [direct]
  22. Environment Variables [direct]
  23. Errors [direct]
  24. Events [direct]
  25. File system [direct]
  26. Globals [direct]
  27. HTTP [direct]
  28. HTTP/2 [direct]
  29. HTTPS [direct]
  30. Inspector [direct]
  31. Internationalization [direct]
  32. Modules: CommonJS modules [direct]
  33. Modules: ECMAScript modules [direct]
  34. Modules: node:module API [direct]
  35. Modules: Packages [direct]
  36. Modules: TypeScript [direct]
  37. Net [direct]
  38. Path [direct]
  39. Performance hooks [direct]
  40. Permissions [direct]
  41. Process [direct]
  42. Punycode [direct]
  43. Query strings [direct]
  44. Readline [direct]
  45. REPL [direct]
  46. Report [direct]
  47. Single executable applications [direct]
  48. SQLite [direct]
  49. Stream [direct]
  50. String decoder [direct]
  51. Test runner [direct]
  52. Timers [direct]
  53. TLS/SSL [direct]
  54. Trace events [direct]
  55. TTY [direct]
  56. UDP/datagram [direct]
  57. URL [direct]
  58. Utilities [direct]
  59. V8 [direct]
  60. VM [direct]
  61. WASI [direct]
  62. Web Crypto API [direct]
  63. Web Streams API [direct]
  64. Worker threads [direct]
  65. Zlib [direct]
  66. Code repository and issue tracker [direct]
  67. Index [direct]
  68. 26.x [direct]
  69. 25.x [direct]
  70. 24.x LTS [direct]
  71. 23.x [direct]
  72. 21.x [direct]
  73. 20.x [direct]
  74. 19.x [direct]
  75. 18.x [direct]
  76. 17.x [direct]
  77. 16.x [direct]
  78. 15.x [direct]
  79. 14.x [direct]
  80. 13.x [direct]