2015-02-26 22:57:45 +01:00
|
|
|
# OS
|
2012-02-27 20:09:34 +01:00
|
|
|
|
2015-02-25 01:15:26 +01:00
|
|
|
Stability: 2 - Stable
|
2012-03-03 00:14:03 +01:00
|
|
|
|
2012-02-27 20:09:34 +01:00
|
|
|
Provides a few basic operating-system related utility functions.
|
2010-12-11 09:49:38 +01:00
|
|
|
|
|
|
|
Use `require('os')` to access this module.
|
|
|
|
|
2015-11-04 18:19:49 +01:00
|
|
|
## os.EOL
|
2011-04-27 05:02:54 +02:00
|
|
|
|
2015-11-04 18:19:49 +01:00
|
|
|
A constant defining the appropriate End-of-line marker for the operating
|
|
|
|
system.
|
2011-04-27 05:02:54 +02:00
|
|
|
|
2012-02-27 20:09:34 +01:00
|
|
|
## os.arch()
|
2011-04-27 05:02:54 +02:00
|
|
|
|
2015-02-26 22:57:45 +01:00
|
|
|
Returns the operating system CPU architecture. Possible values are `'x64'`,
|
2016-01-31 15:38:04 +01:00
|
|
|
`'arm'` and `'ia32'`. Returns the value of [`process.arch`][].
|
2011-04-27 05:02:54 +02:00
|
|
|
|
2012-02-27 20:09:34 +01:00
|
|
|
## os.cpus()
|
2010-12-22 19:55:47 +01:00
|
|
|
|
2012-12-31 19:44:51 +01:00
|
|
|
Returns an array of objects containing information about each CPU/core
|
|
|
|
installed: model, speed (in MHz), and times (an object containing the number of
|
|
|
|
milliseconds the CPU/core spent in: user, nice, sys, idle, and irq).
|
2010-12-22 19:55:47 +01:00
|
|
|
|
|
|
|
Example inspection of os.cpus:
|
|
|
|
|
2016-01-17 18:39:07 +01:00
|
|
|
```js
|
|
|
|
[ { 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 } },
|
|
|
|
{ model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
|
|
|
|
speed: 2926,
|
|
|
|
times:
|
|
|
|
{ user: 511580,
|
|
|
|
nice: 20,
|
|
|
|
sys: 40900,
|
|
|
|
idle: 1070842510,
|
|
|
|
irq: 0 } },
|
|
|
|
{ model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
|
|
|
|
speed: 2926,
|
|
|
|
times:
|
|
|
|
{ user: 291660,
|
|
|
|
nice: 0,
|
|
|
|
sys: 34360,
|
|
|
|
idle: 1070888000,
|
|
|
|
irq: 10 } },
|
|
|
|
{ model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
|
|
|
|
speed: 2926,
|
|
|
|
times:
|
|
|
|
{ user: 308260,
|
|
|
|
nice: 0,
|
|
|
|
sys: 55410,
|
|
|
|
idle: 1071129970,
|
|
|
|
irq: 880 } },
|
|
|
|
{ model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
|
|
|
|
speed: 2926,
|
|
|
|
times:
|
|
|
|
{ user: 266450,
|
|
|
|
nice: 1480,
|
|
|
|
sys: 34920,
|
|
|
|
idle: 1072572010,
|
|
|
|
irq: 30 } } ]
|
|
|
|
```
|
2011-03-17 00:31:38 +01:00
|
|
|
|
2015-02-26 22:57:45 +01:00
|
|
|
Note that since `nice` values are UNIX centric in Windows the `nice` values of
|
|
|
|
all processors are always 0.
|
|
|
|
|
2015-11-04 18:19:49 +01:00
|
|
|
## os.endianness()
|
|
|
|
|
|
|
|
Returns the endianness of the CPU. Possible values are `'BE'` for big endian
|
|
|
|
or `'LE'` for little endian.
|
|
|
|
|
|
|
|
## os.freemem()
|
|
|
|
|
|
|
|
Returns the amount of free system memory in bytes.
|
|
|
|
|
|
|
|
## os.homedir()
|
|
|
|
|
|
|
|
Returns the home directory of the current user.
|
|
|
|
|
|
|
|
## os.hostname()
|
|
|
|
|
|
|
|
Returns the hostname of the operating system.
|
|
|
|
|
|
|
|
## os.loadavg()
|
|
|
|
|
|
|
|
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. As a rule of thumb, the load
|
|
|
|
average should ideally be less than the number of logical CPUs in the system.
|
|
|
|
|
|
|
|
The load average is a very UNIX-y concept; there is no real equivalent on
|
|
|
|
Windows platforms. That is why this function always returns `[0, 0, 0]` on
|
|
|
|
Windows.
|
|
|
|
|
2012-02-27 20:09:34 +01:00
|
|
|
## os.networkInterfaces()
|
2011-03-17 00:31:38 +01:00
|
|
|
|
|
|
|
Get a list of network interfaces:
|
|
|
|
|
2016-01-17 18:39:07 +01:00
|
|
|
```js
|
|
|
|
{ lo:
|
|
|
|
[ { address: '127.0.0.1',
|
|
|
|
netmask: '255.0.0.0',
|
|
|
|
family: 'IPv4',
|
|
|
|
mac: '00:00:00:00:00:00',
|
|
|
|
internal: true },
|
|
|
|
{ address: '::1',
|
|
|
|
netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
|
|
|
|
family: 'IPv6',
|
|
|
|
mac: '00:00:00:00:00:00',
|
|
|
|
internal: true } ],
|
|
|
|
eth0:
|
|
|
|
[ { address: '192.168.1.108',
|
|
|
|
netmask: '255.255.255.0',
|
|
|
|
family: 'IPv4',
|
|
|
|
mac: '01:02:03:0a:0b:0c',
|
|
|
|
internal: false },
|
|
|
|
{ address: 'fe80::a00:27ff:fe4e:66a1',
|
|
|
|
netmask: 'ffff:ffff:ffff:ffff::',
|
|
|
|
family: 'IPv6',
|
|
|
|
mac: '01:02:03:0a:0b:0c',
|
|
|
|
internal: false } ] }
|
|
|
|
```
|
2011-03-17 00:31:38 +01:00
|
|
|
|
2015-01-21 20:32:37 +01:00
|
|
|
Note that due to the underlying implementation this will only return network
|
|
|
|
interfaces that have been assigned an address.
|
|
|
|
|
2015-11-04 18:19:49 +01:00
|
|
|
## os.platform()
|
2012-04-12 10:29:15 +02:00
|
|
|
|
2015-11-04 18:19:49 +01:00
|
|
|
Returns the operating system platform. Possible values are `'darwin'`,
|
|
|
|
`'freebsd'`, `'linux'`, `'sunos'` or `'win32'`. Returns the value of
|
2016-01-31 15:38:04 +01:00
|
|
|
[`process.platform`][].
|
2015-11-04 18:19:49 +01:00
|
|
|
|
|
|
|
## os.release()
|
|
|
|
|
|
|
|
Returns the operating system release.
|
|
|
|
|
|
|
|
## os.tmpdir()
|
|
|
|
|
|
|
|
Returns the operating system's default directory for temporary files.
|
|
|
|
|
|
|
|
## os.totalmem()
|
|
|
|
|
|
|
|
Returns the total amount of system memory in bytes.
|
|
|
|
|
|
|
|
## os.type()
|
|
|
|
|
|
|
|
Returns the operating system name. For example `'Linux'` on Linux, `'Darwin'`
|
|
|
|
on OS X and `'Windows_NT'` on Windows.
|
|
|
|
|
|
|
|
## os.uptime()
|
|
|
|
|
|
|
|
Returns the system uptime in seconds.
|
2016-01-31 15:38:04 +01:00
|
|
|
|
2016-04-07 19:45:40 +02:00
|
|
|
## os.userInfo([options])
|
|
|
|
|
|
|
|
* `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 a subset of the password file entry for the current effective user. 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 `userInfo()` comes directly from the
|
|
|
|
operating system. This differs from the result of `os.homedir()`, which queries
|
|
|
|
several environment variables for the home directory before falling back to the
|
|
|
|
operating system response.
|
|
|
|
|
2016-01-31 15:38:04 +01:00
|
|
|
[`process.arch`]: process.html#process_process_arch
|
|
|
|
[`process.platform`]: process.html#process_process_platform
|