本文共 4464 字,大约阅读时间需要 14 分钟。
This module provides many functions that you can use to retrieve information from the underlying operating system and the computer the program runs on, and interact with it.
该模块提供了许多功能,可用于从底层操作系统和程序运行所在的计算机上检索信息,并与其进行交互。
const os = require('os')
There are a few useful properties that tell us some key things related to handling files:
有一些有用的属性可以告诉我们一些与处理文件有关的关键事项:
os.EOL
gives the line delimiter sequence. It’s \n
on Linux and macOS, and \r\n
on Windows.
os.EOL
给os.EOL
定界符序列。 这是\n
在Linux和MacOS和\r\n
在Windows上。
When I say Linux and macOS I mean POSIX platforms. For simplicity I exclude other less popular operating systems Node can run on.
当我说Linux和macOS时,我的意思是POSIX平台。 为简单起见,我排除了Node可以运行的其他较不流行的操作系统。
os.constants.signals
tells us all the constants related to handling process signals, like SIGHUP, SIGKILL and so on.
os.constants.signals
告诉我们所有与处理过程信号相关的常量,例如SIGHUP,SIGKILL等。
os.constants.errno
sets the constants for error reporting, like EADDRINUSE, EOVERFLOW and more.
os.constants.errno
设置用于错误报告的常量,例如EADDRINUSE,EOVERFLOW等。
You can read them all on .
您可以在上阅读所有内容。
Let’s now see the main methods that os
provides:
现在让我们看一下os
提供的主要方法:
os.arch()
(os.arch()
)Return the string that identifies the underlying architecture, like arm
, x64
, arm64
.
返回标识基础架构的字符串,例如arm
, x64
, arm64
。
os.cpus()
(os.cpus()
)Return information on the CPUs available on your system.
返回有关系统上可用CPU的信息。
Example:
例:
[ { model: 'Intel(R) Core(TM)2 Duo CPU P8600 @ 2.40GHz', speed: 2400, times: { user: 281685380, nice: 0, sys: 187986530, idle: 685833750, irq: 0 } }, { model: 'Intel(R) Core(TM)2 Duo CPU P8600 @ 2.40GHz', speed: 2400, times: { user: 282348700, nice: 0, sys: 161800480, idle: 703509470, irq: 0 } } ]
os.endianness()
(os.endianness()
)Return BE
or LE
depending if Node was compiled with .
根据节点是使用编译返回BE
或LE
。
os.freemem()
(os.freemem()
)Return the number of bytes that represent the free memory in the system.
返回代表系统中可用内存的字节数。
os.homedir()
(os.homedir()
)Return the path to the home directory of the current user.
将路径返回到当前用户的主目录。
Example:
例:
'/Users/flavio'
os.hostname()
(os.hostname()
)Return the hostname.
返回主机名。
os.loadavg()
(os.loadavg()
)Return the calculation made by the operating system on the load average.
返回操作系统对平均负载的计算。
It only returns a meaningful value on Linux and macOS.
它仅在Linux和macOS上返回有意义的值。
Example:
例:
[ 3.68798828125, 4.00244140625, 11.1181640625 ]
os.networkInterfaces()
(os.networkInterfaces()
)Returns the details of the network interfaces available on your system.
返回系统上可用网络接口的详细信息。
Example:
例:
{ lo0: [ { address: '127.0.0.1', netmask: '255.0.0.0', family: 'IPv4', mac: 'fe:82:00:00:00:00', internal: true }, { address: '::1', netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', family: 'IPv6', mac: 'fe:82:00:00:00:00', scopeid: 0, internal: true }, { address: 'fe80::1', netmask: 'ffff:ffff:ffff:ffff::', family: 'IPv6', mac: 'fe:82:00:00:00:00', scopeid: 1, internal: true } ], en1: [ { address: 'fe82::9b:8282:d7e6:496e', netmask: 'ffff:ffff:ffff:ffff::', family: 'IPv6', mac: '06:00:00:02:0e:00', scopeid: 5, internal: false }, { address: '192.168.1.38', netmask: '255.255.255.0', family: 'IPv4', mac: '06:00:00:02:0e:00', internal: false } ], utun0: [ { address: 'fe80::2513:72bc:f405:61d0', netmask: 'ffff:ffff:ffff:ffff::', family: 'IPv6', mac: 'fe:80:00:20:00:00', scopeid: 8, internal: false } ] }
os.platform()
(os.platform()
)Return the platform that Node was compiled for:
返回为Node编译的平台:
darwin
darwin
freebsd
freebsd
linux
linux
openbsd
openbsd
win32
win32
os.release()
(os.release()
)Returns a string that identifies the operating system release number
返回标识操作系统版本号的字符串
os.tmpdir()
(os.tmpdir()
)Returns the path to the assigned temp folder.
返回指定的临时文件夹的路径。
os.totalmem()
(os.totalmem()
)Returns the number of bytes that represent the total memory available in the system.
返回表示系统中可用总内存的字节数。
os.type()
(os.type()
)Identifies the operating system:
标识操作系统:
Linux
Linux
Darwin
on macOS
Darwin
在macOS上
Windows_NT
on Windows
Windows上的Windows_NT
os.uptime()
(os.uptime()
)Returns the number of seconds the computer has been running since it was last rebooted.
返回自上次重新启动以来计算机一直在运行的秒数。
os.userInfo()
(os.userInfo()
)Returns information about the current user
返回有关当前用户的信息
翻译自:
转载地址:http://yoqgb.baihongyu.com/