os
The node:os module provides operating system-related utility methods and
properties. It can be accessed using:
import os from 'node:os';
Usage in Deno
import * as mod from "node:os";
Functions
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'.
Returns an estimate of the default amount of parallelism a program should use. Always returns a value greater than zero.
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.
Returns a string identifying the endianness of the CPU for which the Node.js binary was compiled.
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.
Returns the machine type as a string, such as arm, arm64, aarch64, mips, mips64, ppc64, ppc64le, s390, s390x, i386, i686, x86_64.
Returns an object containing network interfaces that have been assigned a network address.
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'.
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.
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.
Interfaces
Namespaces
Type Aliases
Variables
function arch
Usage in Deno
import { arch } from "node:os";
#arch(): stringReturns 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.
Return Type #
string function availableParallelism
Usage in Deno
import { availableParallelism } from "node:os";
#availableParallelism(): numberReturns 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().
Return Type #
number function cpus
Usage in Deno
import { cpus } from "node:os";
#cpus(): CpuInfo[]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: '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,
},
},
]
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 availableParallelism for this purpose.
Return Type #
CpuInfo[] function endianness
Usage in Deno
import { endianness } from "node:os";
function getPriority
Usage in Deno
import { getPriority } from "node:os";
function homedir
Usage in Deno
import { homedir } from "node:os";
#homedir(): stringReturns 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.
Return Type #
string function loadavg
Usage in Deno
import { loadavg } from "node:os";
#loadavg(): 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].
Return Type #
number[] function machine
Usage in Deno
import { machine } from "node:os";
#machine(): stringReturns 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.
Return Type #
string function networkInterfaces
Usage in Deno
import { networkInterfaces } from "node:os";
#networkInterfaces(): Dict<NetworkInterfaceInfo[]>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:
{
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'
}
]
}
Return Type #
Dict<NetworkInterfaceInfo[]> function platform
Usage in Deno
import { platform } from "node:os";
#platform(): PlatformReturns 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.
Return Type #
Platform function release
Usage in Deno
import { release } from "node:os";
#release(): stringReturns 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.
Return Type #
string function setPriority
Usage in Deno
import { setPriority } from "node:os";
Overload 1
#setPriority(priority: number): voidAttempts 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.
Parameters #
#priority: number The scheduling priority to assign to the process.
Return Type #
void Overload 2
function type
Usage in Deno
import { type } from "node:os";
#type(): stringReturns 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.
Return Type #
string function userInfo
Usage in Deno
import { userInfo } from "node:os";
Overload 1
#userInfo(options: { encoding: "buffer"; }): UserInfo<Buffer>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.
Parameters #
#options: { encoding: "buffer"; } Return Type #
UserInfo<Buffer> Overload 2
function version
Usage in Deno
import { version } from "node:os";
#version(): stringReturns 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.
Return Type #
string interface CpuInfo
Usage in Deno
import { type CpuInfo } from "node:os";
interface NetworkInterfaceInfoIPv4
Usage in Deno
import { type NetworkInterfaceInfoIPv4 } from "node:os";
interface NetworkInterfaceInfoIPv6
Usage in Deno
import { type NetworkInterfaceInfoIPv6 } from "node:os";
namespace constants.errno
Usage in Deno
import { constants } from "node:os";
Variables #
variable constants.signals
Type #
type alias NetworkInterfaceInfo
Usage in Deno
import { type NetworkInterfaceInfo } from "node:os";
Definition #
type alias SignalConstants
Usage in Deno
import { type SignalConstants } from "node:os";
Definition #
[key in Signals]: number variable constants.dlopen.RTLD_DEEPBIND
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.EADDRNOTAVAIL
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.EPROTONOSUPPORT
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSA_E_CANCELLED
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSA_E_NO_MORE
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAEADDRINUSE
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAEADDRNOTAVAIL
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAEAFNOSUPPORT
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAECANCELLED
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAECONNABORTED
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAECONNREFUSED
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAECONNRESET
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAEDESTADDRREQ
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAEHOSTUNREACH
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAEINPROGRESS
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAEINVALIDPROCTABLE
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAEINVALIDPROVIDER
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAENAMETOOLONG
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAENETUNREACH
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAENOPROTOOPT
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAEOPNOTSUPP
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAEPFNOSUPPORT
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAEPROTONOSUPPORT
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAEPROTOTYPE
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAEPROVIDERFAILEDINIT
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAESOCKTNOSUPPORT
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAETOOMANYREFS
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAEWOULDBLOCK
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSANOTINITIALISED
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSASERVICE_NOT_FOUND
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSASYSCALLFAILURE
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSASYSNOTREADY
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSATYPE_NOT_FOUND
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.errno.WSAVERNOTSUPPORTED
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.priority.PRIORITY_ABOVE_NORMAL
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.priority.PRIORITY_BELOW_NORMAL
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.priority.PRIORITY_HIGH
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.priority.PRIORITY_HIGHEST
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.priority.PRIORITY_LOW
Usage in Deno
import { constants } from "node:os";
Type #
number variable constants.priority.PRIORITY_NORMAL
Usage in Deno
import { constants } from "node:os";
Type #
number