{ "source": "doc/api/os.md", "modules": [ { "textRaw": "OS", "name": "os", "stability": 2, "stabilityText": "Stable", "desc": "
The os
module provides a number of operating system-related utility methods.\nIt can be accessed using:
const os = require('os');\n
\n",
"properties": [
{
"textRaw": "`EOL` {String} ",
"type": "String",
"name": "EOL",
"meta": {
"added": [
"v0.7.8"
]
},
"desc": "A string constant defining the operating system-specific end-of-line marker:
\n\\n
on POSIX\\r\\n
on WindowsReturns an object containing commonly used operating system specific constants\nfor error codes, process signals, and so on. The specific constants currently\ndefined are described in OS Constants.
\n" } ], "methods": [ { "textRaw": "os.arch()", "type": "method", "name": "arch", "meta": { "added": [ "v0.5.0" ] }, "signatures": [ { "return": { "textRaw": "Returns: {String} ", "name": "return", "type": "String" }, "params": [] }, { "params": [] } ], "desc": "The os.arch()
method returns a string identifying the operating system CPU\narchitecture for which the Node.js binary was compiled.
The current possible values are: 'arm'
, 'arm64'
, 'ia32'
, 'mips'
,\n'mipsel'
, 'ppc'
, 'ppc64'
, 's390'
, 's390x'
, 'x32'
, 'x64'
, and\n'x86'
.
Equivalent to process.arch
.
The os.cpus()
method returns an array of objects containing information about\neach CPU/core installed.
The properties included on each object include:
\nmodel
{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.For example:
\n[\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 model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',\n speed: 2926,\n times: {\n user: 511580,\n nice: 20,\n sys: 40900,\n idle: 1070842510,\n irq: 0\n }\n },\n {\n model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',\n speed: 2926,\n times: {\n user: 291660,\n nice: 0,\n sys: 34360,\n idle: 1070888000,\n irq: 10\n }\n },\n {\n model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',\n speed: 2926,\n times: {\n user: 308260,\n nice: 0,\n sys: 55410,\n idle: 1071129970,\n irq: 880\n }\n },\n {\n model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',\n speed: 2926,\n times: {\n user: 266450,\n nice: 1480,\n sys: 34920,\n idle: 1072572010,\n irq: 30\n }\n }\n]\n
\nNote: Because nice
values are UNIX-specific, on Windows the nice
values of\nall processors are always 0.
The os.endianness()
method returns a string identifying the endianness of the\nCPU for which the Node.js binary was compiled.
Possible values are:
\n'BE'
for big endian'LE'
for little endian.The os.freemem()
method returns the amount of free system memory in bytes as\nan integer.
The os.homedir()
method returns the home directory of the current user as a\nstring.
The os.hostname()
method returns the hostname of the operating system as a\nstring.
The os.loadavg()
method returns an array containing the 1, 5, and 15 minute\nload averages.
The load average is a measure of system activity, calculated by the operating\nsystem and expressed as a fractional number. As a rule of thumb, the load\naverage should ideally be less than the number of logical CPUs in the system.
\nThe load average is a UNIX-specific concept with no real equivalent on\nWindows platforms. On Windows, the return value is always [0, 0, 0]
.
The os.networkInterfaces()
method returns an object containing only network\ninterfaces that have been assigned a network 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.
\nThe properties available on the assigned network address object include:
\naddress
{String} The assigned IPv4 or IPv6 addressnetmask
{String} The IPv4 or IPv6 network maskfamily
{String} Either IPv4
or IPv6
mac
{String} The MAC address of the network interfaceinternal
{boolean} true
if the network interface is a loopback or\nsimilar interface that is not remotely accessible; otherwise false
scopeid
{number} The numeric IPv6 scope ID (only specified when family
\nis IPv6
){\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 },\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 internal: true\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 },\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 internal: false\n }\n ]\n}\n
\n"
},
{
"textRaw": "os.platform()",
"type": "method",
"name": "platform",
"meta": {
"added": [
"v0.5.0"
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {String} ",
"name": "return",
"type": "String"
},
"params": []
},
{
"params": []
}
],
"desc": "The os.platform()
method returns a string identifying the operating system\nplatform as set during compile time of Node.js.
Currently possible values are:
\n'aix'
'darwin'
'freebsd'
'linux'
'openbsd'
'sunos'
'win32'
Equivalent to process.platform
.
Note: The value 'android'
may also be returned if the Node.js is built on\nthe Android operating system. However, Android support in Node.js is considered\nto be experimental at this time.
The os.release()
method returns a string identifying the operating system\nrelease.
Note: On POSIX systems, the operating system release is determined by calling\nuname(3). On Windows, GetVersionExW()
is used. Please see\nhttps://en.wikipedia.org/wiki/Uname#Examples for more information.
The os.tmpdir()
method returns a string specifying the operating system's\ndefault directory for temporary files.
The os.totalmem()
method returns the total amount of system memory in bytes\nas an integer.
The os.type()
method returns a string identifying the operating system name\nas returned by uname(3). For example 'Linux'
on Linux, 'Darwin'
on macOS and\n'Windows_NT'
on Windows.
Please see https://en.wikipedia.org/wiki/Uname#Examples for additional\ninformation about the output of running uname(3) on various operating systems.
\n" }, { "textRaw": "os.uptime()", "type": "method", "name": "uptime", "meta": { "added": [ "v0.3.3" ] }, "signatures": [ { "return": { "textRaw": "Returns: {Integer} ", "name": "return", "type": "Integer" }, "params": [] }, { "params": [] } ], "desc": "The os.uptime()
method returns the system uptime in number of seconds.
Note: Within Node.js' internals, this number is represented as a double
.\nHowever, fractional seconds are not returned and the value can typically be\ntreated as an integer.
The os.userInfo()
method returns information about the currently effective\nuser -- on POSIX platforms, this is typically a subset of the password file. The\nreturned object includes the username
, uid
, gid
, shell
, and homedir
.\nOn 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\nsystem. This differs from the result of os.homedir()
, which queries several\nenvironment variables for the home directory before falling back to the\noperating system response.
The following constants are exported by os.constants
. Note: Not all\nconstants will be available on every operating system.
The following signal constants are exported by os.constants.signals
:
Constant | \nDescription | \n
---|---|
SIGHUP | \n Sent to indicate when a controlling terminal is closed or a parent\n process exits. | \n
SIGINT | \n Sent to indicate when a user wishes to interrupt a process\n ((Ctrl+C) ). | \n
SIGQUIT | \n Sent to indicate when a user wishes to terminate a process and perform a\n core dump. | \n
SIGILL | \n Sent to a process to notify that it has attempted to perform an illegal,\n malformed, unknown or privileged instruction. | \n
SIGTRAP | \n Sent to a process when an exception has occurred. | \n
SIGABRT | \n Sent to a process to request that it abort. | \n
SIGIOT | \n Synonym for SIGABRT | \n
SIGBUS | \n Sent to a process to notify that it has caused a bus error. | \n
SIGFPE | \n Sent to a process to notify that it has performed an illegal arithmetic\n operation. | \n
SIGKILL | \n Sent to a process to terminate it immediately. | \n
SIGUSR1 SIGUSR2 | \n Sent to a process to identify user-defined conditions. | \n
SIGSEGV | \n Sent to a process to notify of a segmentation fault. | \n
SIGPIPE | \n Sent to a process when it has attempted to write to a disconnected\n pipe. | \n
SIGALRM | \n Sent to a process when a system timer elapses. | \n
SIGTERM | \n Sent to a process to request termination. | \n
SIGCHLD | \n Sent to a process when a child process terminates. | \n
SIGSTKFLT | \n Sent to a process to indicate a stack fault on a coprocessor. | \n
SIGCONT | \n Sent to instruct the operating system to continue a paused process. | \n
SIGSTOP | \n Sent to instruct the operating system to halt a process. | \n
SIGTSTP | \n Sent to a process to request it to stop. | \n
SIGBREAK | \n Sent to indicate when a user wishes to interrupt a process. | \n
SIGTTIN | \n Sent to a process when it reads from the TTY while in the\n background. | \n
SIGTTOU | \n Sent to a process when it writes to the TTY while in the\n background. | \n
SIGURG | \n Sent to a process when a socket has urgent data to read. | \n
SIGXCPU | \n Sent to a process when it has exceeded its limit on CPU usage. | \n
SIGXFSZ | \n Sent to a process when it grows a file larger than the maximum\n allowed. | \n
SIGVTALRM | \n Sent to a process when a virtual timer has elapsed. | \n
SIGPROF | \n Sent to a process when a system timer has elapsed. | \n
SIGWINCH | \n Sent to a process when the controlling terminal has changed its\n size. | \n
SIGIO | \n Sent to a process when I/O is available. | \n
SIGPOLL | \n Synonym for SIGIO | \n
SIGLOST | \n Sent to a process when a file lock has been lost. | \n
SIGPWR | \n Sent to a process to notify of a power failure. | \n
SIGINFO | \n Synonym for SIGPWR | \n
SIGSYS | \n Sent to a process to notify of a bad argument. | \n
SIGUNUSED | \n Synonym for SIGSYS | \n
The following error constants are exported by os.constants.errno
:
Constant | \nDescription | \n
---|---|
E2BIG | \n Indicates that the list of arguments is longer than expected. | \n
EACCES | \n Indicates that the operation did not have sufficient permissions. | \n
EADDRINUSE | \n Indicates that the network address is already in use. | \n
EADDRNOTAVAIL | \n Indicates that the network address is currently unavailable for\n use. | \n
EAFNOSUPPORT | \n Indicates that the network address family is not supported. | \n
EAGAIN | \n Indicates that there is currently no data available and to try the\n operation again later. | \n
EALREADY | \n Indicates that the socket already has a pending connection in\n progress. | \n
EBADF | \n Indicates that a file descriptor is not valid. | \n
EBADMSG | \n Indicates an invalid data message. | \n
EBUSY | \n Indicates that a device or resource is busy. | \n
ECANCELED | \n Indicates that an operation was canceled. | \n
ECHILD | \n Indicates that there are no child processes. | \n
ECONNABORTED | \n Indicates that the network connection has been aborted. | \n
ECONNREFUSED | \n Indicates that the network connection has been refused. | \n
ECONNRESET | \n Indicates that the network connection has been reset. | \n
EDEADLK | \n Indicates that a resource deadlock has been avoided. | \n
EDESTADDRREQ | \n Indicates that a destination address is required. | \n
EDOM | \n Indicates that an argument is out of the domain of the function. | \n
EDQUOT | \n Indicates that the disk quota has been exceeded. | \n
EEXIST | \n Indicates that the file already exists. | \n
EFAULT | \n Indicates an invalid pointer address. | \n
EFBIG | \n Indicates that the file is too large. | \n
EHOSTUNREACH | \n Indicates that the host is unreachable. | \n
EIDRM | \n Indicates that the identifier has been removed. | \n
EILSEQ | \n Indicates an illegal byte sequence. | \n
EINPROGRESS | \n Indicates that an operation is already in progress. | \n
EINTR | \n Indicates that a function call was interrupted. | \n
EINVAL | \n Indicates that an invalid argument was provided. | \n
EIO | \n Indicates an otherwise unspecified I/O error. | \n
EISCONN | \n Indicates that the socket is connected. | \n
EISDIR | \n Indicates that the path is a directory. | \n
ELOOP | \n Indicates too many levels of symbolic links in a path. | \n
EMFILE | \n Indicates that there are too many open files. | \n
EMLINK | \n Indicates that there are too many hard links to a file. | \n
EMSGSIZE | \n Indicates that the provided message is too long. | \n
EMULTIHOP | \n Indicates that a multihop was attempted. | \n
ENAMETOOLONG | \n Indicates that the filename is too long. | \n
ENETDOWN | \n Indicates that the network is down. | \n
ENETRESET | \n Indicates that the connection has been aborted by the network. | \n
ENETUNREACH | \n Indicates that the network is unreachable. | \n
ENFILE | \n Indicates too many open files in the system. | \n
ENOBUFS | \n Indicates that no buffer space is available. | \n
ENODATA | \n Indicates that no message is available on the stream head read\n queue. | \n
ENODEV | \n Indicates that there is no such device. | \n
ENOENT | \n Indicates that there is no such file or directory. | \n
ENOEXEC | \n Indicates an exec format error. | \n
ENOLCK | \n Indicates that there are no locks available. | \n
ENOLINK | \n Indications that a link has been severed. | \n
ENOMEM | \n Indicates that there is not enough space. | \n
ENOMSG | \n Indicates that there is no message of the desired type. | \n
ENOPROTOOPT | \n Indicates that a given protocol is not available. | \n
ENOSPC | \n Indicates that there is no space available on the device. | \n
ENOSR | \n Indicates that there are no stream resources available. | \n
ENOSTR | \n Indicates that a given resource is not a stream. | \n
ENOSYS | \n Indicates that a function has not been implemented. | \n
ENOTCONN | \n Indicates that the socket is not connected. | \n
ENOTDIR | \n Indicates that the path is not a directory. | \n
ENOTEMPTY | \n Indicates that the directory is not empty. | \n
ENOTSOCK | \n Indicates that the given item is not a socket. | \n
ENOTSUP | \n Indicates that a given operation is not supported. | \n
ENOTTY | \n Indicates an inappropriate I/O control operation. | \n
ENXIO | \n Indicates no such device or address. | \n
EOPNOTSUPP | \n Indicates that an operation is not supported on the socket.\n Note that while ENOTSUP and EOPNOTSUPP have the same value on Linux,\n according to POSIX.1 these error values should be distinct.) | \n
EOVERFLOW | \n Indicates that a value is too large to be stored in a given data\n type. | \n
EPERM | \n Indicates that the operation is not permitted. | \n
EPIPE | \n Indicates a broken pipe. | \n
EPROTO | \n Indicates a protocol error. | \n
EPROTONOSUPPORT | \n Indicates that a protocol is not supported. | \n
EPROTOTYPE | \n Indicates the wrong type of protocol for a socket. | \n
ERANGE | \n Indicates that the results are too large. | \n
EROFS | \n Indicates that the file system is read only. | \n
ESPIPE | \n Indicates an invalid seek operation. | \n
ESRCH | \n Indicates that there is no such process. | \n
ESTALE | \n Indicates that the file handle is stale. | \n
ETIME | \n Indicates an expired timer. | \n
ETIMEDOUT | \n Indicates that the connection timed out. | \n
ETXTBSY | \n Indicates that a text file is busy. | \n
EWOULDBLOCK | \n Indicates that the operation would block. | \n
EXDEV | \n Indicates an improper link.\n |
The following error codes are specific to the Windows operating system:
\nConstant | \nDescription | \n
---|---|
WSAEINTR | \n Indicates an interrupted function call. | \n
WSAEBADF | \n Indicates an invalid file handle. | \n
WSAEACCES | \n Indicates insufficient permissions to complete the operation. | \n
WSAEFAULT | \n Indicates an invalid pointer address. | \n
WSAEINVAL | \n Indicates that an invalid argument was passed. | \n
WSAEMFILE | \n Indicates that there are too many open files. | \n
WSAEWOULDBLOCK | \n Indicates that a resource is temporarily unavailable. | \n
WSAEINPROGRESS | \n Indicates that an operation is currently in progress. | \n
WSAEALREADY | \n Indicates that an operation is already in progress. | \n
WSAENOTSOCK | \n Indicates that the resource is not a socket. | \n
WSAEDESTADDRREQ | \n Indicates that a destination address is required. | \n
WSAEMSGSIZE | \n Indicates that the message size is too long. | \n
WSAEPROTOTYPE | \n Indicates the wrong protocol type for the socket. | \n
WSAENOPROTOOPT | \n Indicates a bad protocol option. | \n
WSAEPROTONOSUPPORT | \n Indicates that the protocol is not supported. | \n
WSAESOCKTNOSUPPORT | \n Indicates that the socket type is not supported. | \n
WSAEOPNOTSUPP | \n Indicates that the operation is not supported. | \n
WSAEPFNOSUPPORT | \n Indicates that the protocol family is not supported. | \n
WSAEAFNOSUPPORT | \n Indicates that the address family is not supported. | \n
WSAEADDRINUSE | \n Indicates that the network address is already in use. | \n
WSAEADDRNOTAVAIL | \n Indicates that the network address is not available. | \n
WSAENETDOWN | \n Indicates that the network is down. | \n
WSAENETUNREACH | \n Indicates that the network is unreachable. | \n
WSAENETRESET | \n Indicates that the network connection has been reset. | \n
WSAECONNABORTED | \n Indicates that the connection has been aborted. | \n
WSAECONNRESET | \n Indicates that the connection has been reset by the peer. | \n
WSAENOBUFS | \n Indicates that there is no buffer space available. | \n
WSAEISCONN | \n Indicates that the socket is already connected. | \n
WSAENOTCONN | \n Indicates that the socket is not connected. | \n
WSAESHUTDOWN | \n Indicates that data cannot be sent after the socket has been\n shutdown. | \n
WSAETOOMANYREFS | \n Indicates that there are too many references. | \n
WSAETIMEDOUT | \n Indicates that the connection has timed out. | \n
WSAECONNREFUSED | \n Indicates that the connection has been refused. | \n
WSAELOOP | \n Indicates that a name cannot be translated. | \n
WSAENAMETOOLONG | \n Indicates that a name was too long. | \n
WSAEHOSTDOWN | \n Indicates that a network host is down. | \n
WSAEHOSTUNREACH | \n Indicates that there is no route to a network host. | \n
WSAENOTEMPTY | \n Indicates that the directory is not empty. | \n
WSAEPROCLIM | \n Indicates that there are too many processes. | \n
WSAEUSERS | \n Indicates that the user quota has been exceeded. | \n
WSAEDQUOT | \n Indicates that the disk quota has been exceeded. | \n
WSAESTALE | \n Indicates a stale file handle reference. | \n
WSAEREMOTE | \n Indicates that the item is remote. | \n
WSASYSNOTREADY | \n Indicates that the network subsystem is not ready. | \n
WSAVERNOTSUPPORTED | \n Indicates that the winsock.dll version is out of range. | \n
WSANOTINITIALISED | \n Indicates that successful WSAStartup has not yet been performed. | \n
WSAEDISCON | \n Indicates that a graceful shutdown is in progress. | \n
WSAENOMORE | \n Indicates that there are no more results. | \n
WSAECANCELLED | \n Indicates that an operation has been canceled. | \n
WSAEINVALIDPROCTABLE | \n Indicates that the procedure call table is invalid. | \n
WSAEINVALIDPROVIDER | \n Indicates an invalid service provider. | \n
WSAEPROVIDERFAILEDINIT | \n Indicates that the service provider failed to initialized. | \n
WSASYSCALLFAILURE | \n Indicates a system call failure. | \n
WSASERVICE_NOT_FOUND | \n Indicates that a service was not found. | \n
WSATYPE_NOT_FOUND | \n Indicates that a class type was not found. | \n
WSA_E_NO_MORE | \n Indicates that there are no more results. | \n
WSA_E_CANCELLED | \n Indicates that the call was canceled. | \n
WSAEREFUSED | \n Indicates that a database query was refused. | \n
Constant | \nDescription | \n
---|---|
UV_UDP_REUSEADDR | \n \n |