Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node API之OS #5

Open
miclay opened this issue Oct 29, 2013 · 0 comments
Open

Node API之OS #5

miclay opened this issue Oct 29, 2013 · 0 comments
Labels
Milestone

Comments

@miclay
Copy link
Owner

miclay commented Oct 29, 2013

var os=require('os');

os.tmpdir()

返回操作系统默认的临时文件目录。

Mac下:

os.tmpdir()
'/var/folders/db/k33xy5d567l2_pvyl4hll6jc0000gn/T/'

Win下:

os.tmpdir()
'C:\Users\miclay\AppData\Local\Temp'

os.endianness()

返回 CPU 的字节序, "BE" 或 "LE"。

字节序:是指多字节数据在计算机内存中存储或者网络传输时各字节的存储顺序。
Little endian:将低序字节存储在起始地址。
Big endian:将高序字节存储在起始地址。
网络序:采用Big endian排序方式。

IA架构(Intel、AMD)的CPU中是Little-Endian;
PowerPC 、SPARC和Motorola处理器是Big-Endian。

os.hostname()

返回操作系统的主机名。

os.hostname()
'miclay-PC.local'

os.type()

返回操作系统名称。

Mac下:

os.type()
'Darwin'

Win下:

os.type()
'Windows_NT'

Darwin是由苹果电脑于2000年所释出的一个开放原始码操作系统。

os.platform()

返回操作系统平台。

Mac下:

os.platform()
'darwin'

Win下:

os.platform()
'win32'

os.arch()

返回操作系统 CPU 架构,可能的值有 "x64"、"arm" 和 "ia32"。

Mac下:

os.arch()
'x64'

Win下:

os.arch()
'ia32'

os.release()

返回操作系统的发行版本。

os.release()
'12.5.0'

os.uptime()

返回操作系统运行的时间,以秒为单位。

Mac下:

os.uptime()
1794584

Win下:

os.uptime()
99218.599916

os.loadavg()

返回一个包含 1、5、15 分钟平均负载的数组。

os.loadavg()
[ 2.30126953125,
2.2802734375,
2.02880859375 ]

os.totalmem()

返回系统内存总量,单位为字节。

os.totalmem()
8589934592

os.freemem()

返回操作系统空闲内存量,单位是字节。

os.freemem()
126431232

os.cpus()

返回一个对象数组,包含所安装的每个 CPU/内核的信息:型号、速度(单位 MHz)、时间(一个包含 user、nice、sys、idle 和 irq 所使用 CPU/内核毫秒数的对象)。

os.cpus()
[ { model: 'Intel(R) Core(TM) i5-3230M CPU @ 2.60GHz',
speed: 2600,
times:
{ user: 92683640,
nice: 0,
sys: 51859340,
idle: 346731810,
irq: 0 } },
{ model: 'Intel(R) Core(TM) i5-3230M CPU @ 2.60GHz',
speed: 2600,
times:
{ user: 64867920,
nice: 0,
sys: 22723320,
idle: 403675940,
irq: 0 } },
{ model: 'Intel(R) Core(TM) i5-3230M CPU @ 2.60GHz',
speed: 2600,
times:
{ user: 96433320,
nice: 0,
sys: 46198670,
idle: 348635460,
irq: 0 } },
{ model: 'Intel(R) Core(TM) i5-3230M CPU @ 2.60GHz',
speed: 2600,
times:
{ user: 65616080,
nice: 0,
sys: 23806480,
idle: 401844230,
irq: 0 } } ]

os.networkInterfaces()

获取网络接口的一个列表信息。

Mac下:

os.networkInterfaces()
{ lo0:
[ { address: 'fe80::1',
family: 'IPv6',
internal: true },
{ address: '127.0.0.1',
family: 'IPv4',
internal: true },
{ address: '::1',
family: 'IPv6',
internal: true } ],
en0:
[ { address: 'fe80::5626:96ff:fed3:f259',
family: 'IPv6',
internal: false },
{ address: '10.32.183.106',
family: 'IPv4',
internal: false } ],
vmnet1:
[ { address: '192.168.155.1',
family: 'IPv4',
internal: false } ],
vmnet8:
[ { address: '172.16.102.1',
family: 'IPv4',
internal: false } ] }

Win下:

os.networkInterfaces()
{ '本地连接':
[ { address: 'fe80::bdf6:84d7:75bb:8ed3',
family: 'IPv6',
internal: false },
{ address: '172.16.102.129',
family: 'IPv4',
internal: false } ],
'Loopback Pseudo-Interface 1':
[ { address: '::1',
family: 'IPv6',
internal: true },
{ address: '127.0.0.1',
family: 'IPv4',
internal: true } ],
'本地连接* 4':
[ { address: '2001:0:9d38:6abd:c00:15d9:53ef:997e',
family: 'IPv6',
internal: false },
{ address: 'fe80::c00:15d9:53ef:997e',
family: 'IPv6',
internal: false } ] }

os.EOL

一个定义了操作系统的一行结束的标识的常量。

Mac下:

os.EOL
'\n'

Win下:

os.EOL
'\r\n'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant