doc: sort globals alphabetically
[platform/upstream/nodejs.git] / doc / api / os.markdown
1 # OS
2
3     Stability: 2 - Stable
4
5 Provides a few basic operating-system related utility functions.
6
7 Use `require('os')` to access this module.
8
9 ## os.tmpdir()
10
11 Returns the operating system's default directory for temporary files.
12
13 ## os.homedir()
14
15 Returns the home directory of the current user.
16
17 ## os.endianness()
18
19 Returns the endianness of the CPU. Possible values are `'BE'` for big endian
20 or `'LE'` for little endian.
21
22 ## os.hostname()
23
24 Returns the hostname of the operating system.
25
26 ## os.type()
27
28 Returns the operating system name. For example `'Linux'` on Linux, `'Darwin'`
29 on OS X and `'Windows_NT'` on Windows.
30
31 ## os.platform()
32
33 Returns the operating system platform. Possible values are `'darwin'`,
34 `'freebsd'`, `'linux'`, `'sunos'` or `'win32'`. Returns the value of
35 `process.platform`.
36
37 ## os.arch()
38
39 Returns the operating system CPU architecture. Possible values are `'x64'`,
40 `'arm'` and `'ia32'`. Returns the value of `process.arch`.
41
42 ## os.release()
43
44 Returns the operating system release.
45
46 ## os.uptime()
47
48 Returns the system uptime in seconds.
49
50 ## os.loadavg()
51
52 Returns an array containing the 1, 5, and 15 minute load averages.
53
54 The load average is a measure of system activity, calculated by the operating
55 system and expressed as a fractional number.  As a rule of thumb, the load
56 average should ideally be less than the number of logical CPUs in the system.
57
58 The load average is a very UNIX-y concept; there is no real equivalent on
59 Windows platforms.  That is why this function always returns `[0, 0, 0]` on
60 Windows.
61
62 ## os.totalmem()
63
64 Returns the total amount of system memory in bytes.
65
66 ## os.freemem()
67
68 Returns the amount of free system memory in bytes.
69
70 ## os.cpus()
71
72 Returns an array of objects containing information about each CPU/core
73 installed: model, speed (in MHz), and times (an object containing the number of
74 milliseconds the CPU/core spent in: user, nice, sys, idle, and irq).
75
76 Example inspection of os.cpus:
77
78     [ { model: 'Intel(R) Core(TM) i7 CPU         860  @ 2.80GHz',
79         speed: 2926,
80         times:
81          { user: 252020,
82            nice: 0,
83            sys: 30340,
84            idle: 1070356870,
85            irq: 0 } },
86       { model: 'Intel(R) Core(TM) i7 CPU         860  @ 2.80GHz',
87         speed: 2926,
88         times:
89          { user: 306960,
90            nice: 0,
91            sys: 26980,
92            idle: 1071569080,
93            irq: 0 } },
94       { model: 'Intel(R) Core(TM) i7 CPU         860  @ 2.80GHz',
95         speed: 2926,
96         times:
97          { user: 248450,
98            nice: 0,
99            sys: 21750,
100            idle: 1070919370,
101            irq: 0 } },
102       { model: 'Intel(R) Core(TM) i7 CPU         860  @ 2.80GHz',
103         speed: 2926,
104         times:
105          { user: 256880,
106            nice: 0,
107            sys: 19430,
108            idle: 1070905480,
109            irq: 20 } },
110       { model: 'Intel(R) Core(TM) i7 CPU         860  @ 2.80GHz',
111         speed: 2926,
112         times:
113          { user: 511580,
114            nice: 20,
115            sys: 40900,
116            idle: 1070842510,
117            irq: 0 } },
118       { model: 'Intel(R) Core(TM) i7 CPU         860  @ 2.80GHz',
119         speed: 2926,
120         times:
121          { user: 291660,
122            nice: 0,
123            sys: 34360,
124            idle: 1070888000,
125            irq: 10 } },
126       { model: 'Intel(R) Core(TM) i7 CPU         860  @ 2.80GHz',
127         speed: 2926,
128         times:
129          { user: 308260,
130            nice: 0,
131            sys: 55410,
132            idle: 1071129970,
133            irq: 880 } },
134       { model: 'Intel(R) Core(TM) i7 CPU         860  @ 2.80GHz',
135         speed: 2926,
136         times:
137          { user: 266450,
138            nice: 1480,
139            sys: 34920,
140            idle: 1072572010,
141            irq: 30 } } ]
142
143 Note that since `nice` values are UNIX centric in Windows the `nice` values of
144 all processors are always 0.
145
146 ## os.networkInterfaces()
147
148 Get a list of network interfaces:
149
150     { lo:
151        [ { address: '127.0.0.1',
152            netmask: '255.0.0.0',
153            family: 'IPv4',
154            mac: '00:00:00:00:00:00',
155            internal: true },
156          { address: '::1',
157            netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
158            family: 'IPv6',
159            mac: '00:00:00:00:00:00',
160            internal: true } ],
161       eth0:
162        [ { address: '192.168.1.108',
163            netmask: '255.255.255.0',
164            family: 'IPv4',
165            mac: '01:02:03:0a:0b:0c',
166            internal: false },
167          { address: 'fe80::a00:27ff:fe4e:66a1',
168            netmask: 'ffff:ffff:ffff:ffff::',
169            family: 'IPv6',
170            mac: '01:02:03:0a:0b:0c',
171            internal: false } ] }
172
173 Note that due to the underlying implementation this will only return network
174 interfaces that have been assigned an address.
175
176 ## os.EOL
177
178 A constant defining the appropriate End-of-line marker for the operating
179 system.