博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Node os模块
阅读量:2504 次
发布时间:2019-05-11

本文共 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.EOLos.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.

返回标识基础架构的字符串,例如armx64arm64

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 .

根据节点是使用编译返回BELE

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

  • …more

    …更多

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/

你可能感兴趣的文章
【C#】wpf中的xmlns命名空间为什么是一个网址,代表了什么意思(转载)
查看>>
你不是迷茫,你是自制力不强
查看>>
【转载】setContentView和inflate区别
查看>>
Bootstrap栅格系统
查看>>
自然语言工程师要求
查看>>
Leetcode 452.用最少数量的箭引爆气球
查看>>
【转】Linux设备驱动之Ioctl控制
查看>>
实例说明>
查看>>
日常理财
查看>>
ng-bind-html在ng-repeat中问题的解决办法
查看>>
制定document.getElementByClassName()
查看>>
UVA-315 无向图求割点个数
查看>>
Python学习_4_购物车
查看>>
ubuntu开机自启动
查看>>
【WXS数据类型】Number
查看>>
canvas学习笔记 ---- 1
查看>>
纪念开博客的第一天_(:з」∠)_
查看>>
WechatHelper
查看>>
测试SDWebImage淡入淡出效果在UITableView中的重用显示问题
查看>>
[控件] ChangeColorLabel
查看>>