温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/node/os
点击访问原文链接

Node.js os module | API Reference | Bun

Node.js os module | API Reference | BunBuildDocsReferenceGuidesBlogDiscord/node:osFarchFavailableParallelismNconstantsFcpusVdevNullFendiannessVEOLFfreememFgetPriorityFhomedirFhostnameFloadavgFmachineFnetworkInterfacesFplatformFreleaseFsetPriorityFtmpdirFtotalmemFtypeFuptimeFuserInfoFversion

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/node:osFarchFavailableParallelismNconstantsFcpusVdevNullFendiannessVEOLFfreememFgetPriorityFhomedirFhostnameFloadavgFmachineFnetworkInterfacesFplatformFreleaseFsetPriorityFtmpdirFtotalmemFtypeFuptimeFuserInfoFversion

Node.js module

os

The 'node:os' module provides operating system-related utility methods and properties, such as CPU architecture, memory usage, uptime, user information, network interfaces, and platform details.

It is useful for gathering runtime environment data and making OS-specific decisions.

Works in Bun

Fully implemented. 100% of Node.js's test suite passes.

namespace constantsnamespace dlopenconst RTLD_DEEPBIND: numberconst RTLD_GLOBAL: numberconst RTLD_LAZY: numberconst RTLD_LOCAL: numberconst RTLD_NOW: numbernamespace errnoconst E2BIG: numberconst EACCES: numberconst EADDRINUSE: numberconst EADDRNOTAVAIL: numberconst EAFNOSUPPORT: numberconst EAGAIN: numberconst EALREADY: numberconst EBADF: numberconst EBADMSG: numberconst EBUSY: numberconst ECANCELED: numberconst ECHILD: numberconst ECONNABORTED: numberconst ECONNREFUSED: numberconst ECONNRESET: numberconst EDEADLK: numberconst EDESTADDRREQ: numberconst EDOM: numberconst EDQUOT: numberconst EEXIST: numberconst EFAULT: numberconst EFBIG: numberconst EHOSTUNREACH: numberconst EIDRM: numberconst EILSEQ: numberconst EINPROGRESS: numberconst EINTR: numberconst EINVAL: numberconst EIO: numberconst EISCONN: numberconst EISDIR: numberconst ELOOP: numberconst EMFILE: numberconst EMLINK: numberconst EMSGSIZE: numberconst EMULTIHOP: numberconst ENAMETOOLONG: numberconst ENETDOWN: numberconst ENETRESET: numberconst ENETUNREACH: numberconst ENFILE: numberconst ENOBUFS: numberconst ENODATA: numberconst ENODEV: numberconst ENOENT: numberconst ENOEXEC: numberconst ENOLCK: numberconst ENOLINK: numberconst ENOMEM: numberconst ENOMSG: numberconst ENOPROTOOPT: numberconst ENOSPC: numberconst ENOSR: numberconst ENOSTR: numberconst ENOSYS: numberconst ENOTCONN: numberconst ENOTDIR: numberconst ENOTEMPTY: numberconst ENOTSOCK: numberconst ENOTSUP: numberconst ENOTTY: numberconst ENXIO: numberconst EOPNOTSUPP: numberconst EOVERFLOW: numberconst EPERM: numberconst EPIPE: numberconst EPROTO: numberconst EPROTONOSUPPORT: numberconst EPROTOTYPE: numberconst ERANGE: numberconst EROFS: numberconst ESPIPE: numberconst ESRCH: numberconst ESTALE: numberconst ETIME: numberconst ETIMEDOUT: numberconst ETXTBSY: numberconst EWOULDBLOCK: numberconst EXDEV: numberconst WSA_E_CANCELLED: numberconst WSA_E_NO_MORE: numberconst WSAEACCES: numberconst WSAEADDRINUSE: numberconst WSAEADDRNOTAVAIL: numberconst WSAEAFNOSUPPORT: numberconst WSAEALREADY: numberconst WSAEBADF: numberconst WSAECANCELLED: numberconst WSAECONNABORTED: numberconst WSAECONNREFUSED: numberconst WSAECONNRESET: numberconst WSAEDESTADDRREQ: numberconst WSAEDISCON: numberconst WSAEDQUOT: numberconst WSAEFAULT: numberconst WSAEHOSTDOWN: numberconst WSAEHOSTUNREACH: numberconst WSAEINPROGRESS: numberconst WSAEINTR: numberconst WSAEINVAL: numberconst WSAEINVALIDPROCTABLE: numberconst WSAEINVALIDPROVIDER: numberconst WSAEISCONN: numberconst WSAELOOP: numberconst WSAEMFILE: numberconst WSAEMSGSIZE: numberconst WSAENAMETOOLONG: numberconst WSAENETDOWN: numberconst WSAENETRESET: numberconst WSAENETUNREACH: numberconst WSAENOBUFS: numberconst WSAENOMORE: numberconst WSAENOPROTOOPT: numberconst WSAENOTCONN: numberconst WSAENOTEMPTY: numberconst WSAENOTSOCK: numberconst WSAEOPNOTSUPP: numberconst WSAEPFNOSUPPORT: numberconst WSAEPROCLIM: numberconst WSAEPROTONOSUPPORT: numberconst WSAEPROTOTYPE: numberconst WSAEPROVIDERFAILEDINIT: numberconst WSAEREFUSED: numberconst WSAEREMOTE: numberconst WSAESHUTDOWN: numberconst WSAESOCKTNOSUPPORT: numberconst WSAESTALE: numberconst WSAETIMEDOUT: numberconst WSAETOOMANYREFS: numberconst WSAEUSERS: numberconst WSAEWOULDBLOCK: numberconst WSANOTINITIALISED: numberconst WSASERVICE_NOT_FOUND: numberconst WSASYSCALLFAILURE: numberconst WSASYSNOTREADY: numberconst WSATYPE_NOT_FOUND: numberconst WSAVERNOTSUPPORTED: numbernamespace priorityconst PRIORITY_ABOVE_NORMAL: numberconst PRIORITY_BELOW_NORMAL: numberconst PRIORITY_HIGH: numberconst PRIORITY_HIGHEST: numberconst PRIORITY_LOW: numberconst PRIORITY_NORMAL: numbernamespace signalsconst signals: SignalConstantsconst UV_UDP_REUSEADDR: numberconst devNull: stringconst EOL: string

The operating system-specific end-of-line marker.


on POSIX
\r
on Windows
function arch(): Architecture;

Returns the operating system CPU architecture for which the Node.js binary was compiled. Possible values are 'arm', 'arm64', 'ia32', 'loong64', 'mips', 'mipsel', 'ppc64', 'riscv64', 's390x', and 'x64'.

The return value is equivalent to process.arch.

function availableParallelism(): number;

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().

function 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.

function endianness(): 'BE' | 'LE';

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.

function freemem(): number;

Returns the amount of free system memory in bytes as an integer.

function getPriority(pid?: number): number;

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.

@param pid

The process ID to retrieve scheduling priority for.

function homedir(): 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.

function hostname(): string;

Returns the host name of the operating system as a string.

function 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].

function machine(): string;

Returns the machine type as a string, such as arm, arm64, aarch64, mips, mips64, ppc64, ppc64le, 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.

function networkInterfaces(): DictNetworkInterfaceInfo[]>;

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'
}
]
}
function platform(): Platform;

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.

function release(): string;function setPriority(priority: number): void;

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.

@param priority

The scheduling priority to assign to the process.

function setPriority(pid: number,priority: number): void;

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.

@param pid

The process ID to set scheduling priority for.

@param priority

The scheduling priority to assign to the process.

function tmpdir(): string;

Returns the operating system's default directory for temporary files as a string.

function totalmem(): number;

Returns the total amount of system memory in bytes as an integer.

function type(): string;function uptime(): number;

Returns the system uptime in number of seconds.

function userInfo(options?: UserInfoOptionsWithStringEncoding): UserInfostring>;

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.

function userInfo(options: UserInfoOptionsWithBufferEncoding): UserInfoNonSharedBuffer>;

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.

function userInfo(options: UserInfoOptions): UserInfostring | NonSharedBuffer>;

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.

function version(): 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.

Type definitionsinterface CpuInfomodel: stringspeed: numbertimes: { idle: number; irq: number; nice: number; sys: number; user: number }interface NetworkInterfaceBaseaddress: stringcidr: null | stringinternal: booleanmac: stringnetmask: stringscopeid?: numberinterface NetworkInterfaceInfoIPv4address: stringcidr: null | stringfamily: 'IPv4'internal: booleanmac: stringnetmask: stringscopeid?: numberinterface NetworkInterfaceInfoIPv6address: stringcidr: null | stringfamily: 'IPv6'internal: booleanmac: stringnetmask: stringscopeid: numberinterface UserInfoT>gid: numberhomedir: Tshell: null | Tuid: numberusername: Tinterface UserInfoOptionsencoding?: BufferEncoding | 'buffer'interface UserInfoOptionsWithBufferEncodingencoding: 'buffer'interface UserInfoOptionsWithStringEncodingencoding?: BufferEncodingtype NetworkInterfaceInfo = NetworkInterfaceInfoIPv4 | NetworkInterfaceInfoIPv6type SignalConstants = { [K in NodeJS.Signals]: number }

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicense

Baked with ❤️ in San Francisco

We're hiring →

Node.js os module | API Reference | Bun,AI智能索引,全网链接索引,智能导航,网页索引

    The