Source Code: lib/os.js
The node:os module provides operating system-related utility methods and\nproperties. It can be accessed using:
node:os
const os = require('node:os');\n
The operating system-specific end-of-line marker.
\\n
\\r\\n
Contains commonly used operating system-specific constants for error codes,\nprocess signals, and so on. The specific constants defined are described in\nOS constants.
The platform-specific file path of the null device.
\\\\.\\nul
/dev/null
Returns the operating system CPU architecture for which the Node.js binary was\ncompiled. Possible values are 'arm', 'arm64', 'ia32', 'mips',\n'mipsel', 'ppc', 'ppc64', 's390', 's390x', and 'x64'.
'arm'
'arm64'
'ia32'
'mips'
'mipsel'
'ppc'
'ppc64'
's390'
's390x'
'x64'
The return value is equivalent to process.arch.
process.arch
Returns an array of objects containing information about each logical CPU core.
The properties included on each object include:
model
speed
times
user
nice
sys
idle
irq
[\n {\n model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',\n speed: 2926,\n times: {\n user: 252020,\n nice: 0,\n sys: 30340,\n idle: 1070356870,\n irq: 0\n }\n },\n {\n model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',\n speed: 2926,\n times: {\n user: 306960,\n nice: 0,\n sys: 26980,\n idle: 1071569080,\n irq: 0\n }\n },\n {\n model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',\n speed: 2926,\n times: {\n user: 248450,\n nice: 0,\n sys: 21750,\n idle: 1070919370,\n irq: 0\n }\n },\n {\n model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',\n speed: 2926,\n times: {\n user: 256880,\n nice: 0,\n sys: 19430,\n idle: 1070905480,\n irq: 20\n }\n },\n]\n
nice values are POSIX-only. On Windows, the nice values of all processors\nare always 0.
Returns a string identifying the endianness of the CPU for which the Node.js\nbinary was compiled.
Possible values are 'BE' for big endian and 'LE' for little endian.
'BE'
'LE'
Returns the amount of free system memory in bytes as an integer.
Returns the scheduling priority for the process specified by pid. If pid is\nnot provided or is 0, the priority of the current process is returned.
pid
0
Returns the string path of the current user's home directory.
On POSIX, it uses the $HOME environment variable if defined. Otherwise it\nuses the effective UID to look up the user's home directory.
$HOME
On Windows, it uses the USERPROFILE environment variable if defined.\nOtherwise it uses the path to the profile directory of the current user.
USERPROFILE
Returns the host name of the operating system as a string.
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\nsystem and expressed as a fractional number.
The load average is a Unix-specific concept. On Windows, the return value is\nalways [0, 0, 0].
[0, 0, 0]
Returns an object containing network interfaces that have been assigned a\nnetwork address.
Each key on the returned object identifies a network interface. The associated\nvalue is an array of objects that each describe an assigned network address.
The properties available on the assigned network address object include:
address
netmask
family
IPv4
IPv6
mac
internal
true
false
scopeid
cidr
null
{\n lo: [\n {\n address: '127.0.0.1',\n netmask: '255.0.0.0',\n family: 'IPv4',\n mac: '00:00:00:00:00:00',\n internal: true,\n cidr: '127.0.0.1/8'\n },\n {\n address: '::1',\n netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',\n family: 'IPv6',\n mac: '00:00:00:00:00:00',\n scopeid: 0,\n internal: true,\n cidr: '::1/128'\n }\n ],\n eth0: [\n {\n address: '192.168.1.108',\n netmask: '255.255.255.0',\n family: 'IPv4',\n mac: '01:02:03:0a:0b:0c',\n internal: false,\n cidr: '192.168.1.108/24'\n },\n {\n address: 'fe80::a00:27ff:fe4e:66a1',\n netmask: 'ffff:ffff:ffff:ffff::',\n family: 'IPv6',\n mac: '01:02:03:0a:0b:0c',\n scopeid: 1,\n internal: false,\n cidr: 'fe80::a00:27ff:fe4e:66a1/64'\n }\n ]\n}\n
Returns a string identifying the operating system platform for which\nthe Node.js binary was compiled. The value is set at compile time.\nPossible values are 'aix', 'darwin', 'freebsd','linux',\n'openbsd', 'sunos', and 'win32'.
'aix'
'darwin'
'freebsd'
'linux'
'openbsd'
'sunos'
'win32'
The return value is equivalent to process.platform.
process.platform
The value 'android' may also be returned if Node.js is built on the Android\noperating system. Android support is experimental.
'android'
Returns the operating system as a string.
On POSIX systems, the operating system release is determined by calling\nuname(3). On Windows, GetVersionExW() is used. See\nhttps://en.wikipedia.org/wiki/Uname#Examples for more information.
uname(3)
GetVersionExW()
Attempts to set the scheduling priority for the process specified by pid. If\npid 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\n(low priority). Due to differences between Unix priority levels and Windows\npriority classes, priority is mapped to one of six priority constants in\nos.constants.priority. When retrieving a process priority level, this range\nmapping may cause the return value to be slightly different on Windows. To avoid\nconfusion, set priority to one of the priority constants.
priority
-20
19
os.constants.priority
On Windows, setting priority to PRIORITY_HIGHEST requires elevated user\nprivileges. Otherwise the set priority will be silently reduced to\nPRIORITY_HIGH.
PRIORITY_HIGHEST
PRIORITY_HIGH
Returns the operating system's default directory for temporary files as a\nstring.
Returns the total amount of system memory in bytes as an integer.
Returns the operating system name as returned by uname(3). For example, it\nreturns 'Linux' on Linux, 'Darwin' on macOS, and 'Windows_NT' on Windows.
'Linux'
'Darwin'
'Windows_NT'
See https://en.wikipedia.org/wiki/Uname#Examples for additional information\nabout the output of running uname(3) on various operating systems.
Returns the system uptime in number of seconds.
Returns information about the currently effective user. On POSIX platforms,\nthis is typically a subset of the password file. The returned object includes\nthe username, uid, gid, shell, and homedir. On Windows, the uid and\ngid fields are -1, and shell is null.
username
uid
gid
shell
homedir
-1
The value of homedir returned by os.userInfo() is provided by the operating\nsystem. This differs from the result of os.homedir(), which queries\nenvironment variables for the home directory before falling back to the\noperating system response.
os.userInfo()
os.homedir()
Throws a SystemError if a user has no username or homedir.
SystemError
Returns a string identifying the kernel version.
On POSIX systems, the operating system release is determined by calling\nuname(3). On Windows, RtlGetVersion() is used, and if it is not\navailable, GetVersionExW() will be used. See\nhttps://en.wikipedia.org/wiki/Uname#Examples for more information.
RtlGetVersion()
Returns the machine type as a string, such as arm, aarch64, mips,\nmips64, ppc64, ppc64le, s390, s390x, i386, i686, x86_64.
arm
aarch64
mips
mips64
ppc64
ppc64le
s390
s390x
i386
i686
x86_64
On POSIX systems, the machine type is determined by calling\nuname(3). On Windows, RtlGetVersion() is used, and if it is not\navailable, GetVersionExW() will be used. See\nhttps://en.wikipedia.org/wiki/Uname#Examples for more information.
The following constants are exported by os.constants.
os.constants
Not all constants will be available on every operating system.
The following signal constants are exported by os.constants.signals.
os.constants.signals
SIGHUP
SIGINT
SIGQUIT
SIGILL
SIGTRAP
SIGABRT
SIGIOT
SIGBUS
SIGFPE
SIGKILL
SIGUSR1
SIGUSR2
SIGSEGV
SIGPIPE
SIGALRM
SIGTERM
SIGCHLD
SIGSTKFLT
SIGCONT
SIGSTOP
SIGTSTP
SIGBREAK
SIGTTIN
SIGTTOU
SIGURG
SIGXCPU
SIGXFSZ
SIGVTALRM
SIGPROF
SIGWINCH
SIGIO
SIGPOLL
SIGLOST
SIGPWR
SIGINFO
SIGSYS
SIGUNUSED
The following error constants are exported by os.constants.errno.
os.constants.errno
E2BIG
EACCES
EADDRINUSE
EADDRNOTAVAIL
EAFNOSUPPORT
EAGAIN
EALREADY
EBADF
EBADMSG
EBUSY
ECANCELED
ECHILD
ECONNABORTED
ECONNREFUSED
ECONNRESET
EDEADLK
EDESTADDRREQ
EDOM
EDQUOT
EEXIST
EFAULT
EFBIG
EHOSTUNREACH
EIDRM
EILSEQ
EINPROGRESS
EINTR
EINVAL
EIO
EISCONN
EISDIR
ELOOP
EMFILE
EMLINK
EMSGSIZE
EMULTIHOP
ENAMETOOLONG
ENETDOWN
ENETRESET
ENETUNREACH
ENFILE
ENOBUFS
ENODATA
ENODEV
ENOENT
ENOEXEC
ENOLCK
ENOLINK
ENOMEM
ENOMSG
ENOPROTOOPT
ENOSPC
ENOSR
ENOSTR
ENOSYS
ENOTCONN
ENOTDIR
ENOTEMPTY
ENOTSOCK
ENOTSUP
ENOTTY
ENXIO
EOPNOTSUPP
EOVERFLOW
EPERM
EPIPE
EPROTO
EPROTONOSUPPORT
EPROTOTYPE
ERANGE
EROFS
ESPIPE
ESRCH
ESTALE
ETIME
ETIMEDOUT
ETXTBSY
EWOULDBLOCK
EXDEV
The following error codes are specific to the Windows operating system.
WSAEINTR
WSAEBADF
WSAEACCES
WSAEFAULT
WSAEINVAL
WSAEMFILE
WSAEWOULDBLOCK
WSAEINPROGRESS
WSAEALREADY
WSAENOTSOCK
WSAEDESTADDRREQ
WSAEMSGSIZE
WSAEPROTOTYPE
WSAENOPROTOOPT
WSAEPROTONOSUPPORT
WSAESOCKTNOSUPPORT
WSAEOPNOTSUPP
WSAEPFNOSUPPORT
WSAEAFNOSUPPORT
WSAEADDRINUSE
WSAEADDRNOTAVAIL
WSAENETDOWN
WSAENETUNREACH
WSAENETRESET
WSAECONNABORTED
WSAECONNRESET
WSAENOBUFS
WSAEISCONN
WSAENOTCONN
WSAESHUTDOWN
WSAETOOMANYREFS
WSAETIMEDOUT
WSAECONNREFUSED
WSAELOOP
WSAENAMETOOLONG
WSAEHOSTDOWN
WSAEHOSTUNREACH
WSAENOTEMPTY
WSAEPROCLIM
WSAEUSERS
WSAEDQUOT
WSAESTALE
WSAEREMOTE
WSASYSNOTREADY
WSAVERNOTSUPPORTED
winsock.dll
WSANOTINITIALISED
WSAEDISCON
WSAENOMORE
WSAECANCELLED
WSAEINVALIDPROCTABLE
WSAEINVALIDPROVIDER
WSAEPROVIDERFAILEDINIT
WSASYSCALLFAILURE
WSASERVICE_NOT_FOUND
WSATYPE_NOT_FOUND
WSA_E_NO_MORE
WSA_E_CANCELLED
WSAEREFUSED
If available on the operating system, the following constants\nare exported in os.constants.dlopen. See dlopen(3) for detailed\ninformation.
os.constants.dlopen
dlopen(3)
RTLD_LAZY
RTLD_NOW
RTLD_GLOBAL
RTLD_LOCAL
RTLD_DEEPBIND
The following process scheduling constants are exported by\nos.constants.priority.
PRIORITY_LOW
IDLE_PRIORITY_CLASS
PRIORITY_BELOW_NORMAL
PRIORITY_NORMAL
BELOW_NORMAL_PRIORITY_CLASS
10
NORMAL_PRIORITY_CLASS
PRIORITY_ABOVE_NORMAL
ABOVE_NORMAL_PRIORITY_CLASS
-7
HIGH_PRIORITY_CLASS
-14
REALTIME_PRIORITY_CLASS
UV_UDP_REUSEADDR