os

操作系统与文件系统处理模块

使用方法:

var os = require('os');

Field Summary

Type Method and Description
void public static static ServiceServiceService

Service 构造函数,参见 Service

readonly String public static readonly String hostnamehostnamehostname

查询当前运行环境主机名

readonly String public static readonly String typetypetype

查询当前运行环境操作系统名称

readonly String public static readonly String versionversionversion

查询当前运行环境操作系统版本

readonly String public static readonly String archarcharch

查询当前 cpu 环境,可能的结果为 ‘amd64’, ‘arm’, ‘arm64’, ‘ia32’

readonly Integer public static readonly Integer timezonetimezonetimezone

查询运行环境当前时区

readonly String public static readonly String EOLEOLEOL

查询当前运行环境行结尾标识,posix:”\n”;windows:”\r\n”

readonly String public static readonly String execPathexecPathexecPath

查询当前运行执行文件完整路径

Method Summary

Type Method and Description
Number uptime()

查询运行环境运行时间,以秒为单位

Array loadavg()

查询运行环境 1分钟,5分钟,15分钟平均负载

Long totalmem()

查询运行环境总内存,以字节为单位

Long freemem()

查询运行环境可用内存,以字节为单位

Array CPUInfo()

查询当前运行环境 cpu 个数和参数

Integer CPUs()

查询当前运行环境 cpu 个数

String tmpdir()

查询当前运行环境临时文件目录

Object networkInfo()

查询当前运行环境网络信息

Array printerInfo()

查询当前主机的打印机信息

BufferedStream openPrinter(String name)

创建一个打印机输出对象

String platform()

查询当前平台名称,可能的结果为 ‘darwin’, ‘freebsd’, ‘linux’, 或 ‘win32’

Date time(String tmString)

解析时间字符串或查询运行环境当前时间

Date dateAdd(Date d,Integer num,String part)

时间计算函数,根据 part 指定计算时间

Object memoryUsage()

查询当前进程内存使用报告

Field Detail

Service

void public static static ServiceServiceService

Service 构造函数,参见 Service

hostname

readonly String public static readonly String hostnamehostnamehostname

查询当前运行环境主机名

type

readonly String public static readonly String typetypetype

查询当前运行环境操作系统名称

version

readonly String public static readonly String versionversionversion

查询当前运行环境操作系统版本

arch

readonly String public static readonly String archarcharch

查询当前 cpu 环境,可能的结果为 ‘amd64’, ‘arm’, ‘arm64’, ‘ia32’

timezone

readonly Integer public static readonly Integer timezonetimezonetimezone

查询运行环境当前时区

EOL

readonly String public static readonly String EOLEOLEOL

查询当前运行环境行结尾标识,posix:”\n”;windows:”\r\n”

execPath

readonly String public static readonly String execPathexecPathexecPath

查询当前运行执行文件完整路径

Method Detail

uptime

Number uptime()

查询运行环境运行时间,以秒为单位

Returns

返回表示时间的数值

loadavg

Array loadavg()

查询运行环境 1分钟,5分钟,15分钟平均负载

Returns

返回包含三个负载数据的数组

totalmem

Long totalmem()

查询运行环境总内存,以字节为单位

Returns

返回内存数据

freemem

Long freemem()

查询运行环境可用内存,以字节为单位

Returns

返回内存数据

CPUInfo

Array CPUInfo()

查询当前运行环境 cpu 个数和参数

Returns

返回包含 cpu 参数的数组,每一项对应一个 cpu

CPUs

Integer CPUs()

查询当前运行环境 cpu 个数

Returns

返回 cpu 个数

tmpdir

String tmpdir()

查询当前运行环境临时文件目录

Returns

返回临时文件目录

networkInfo

Object networkInfo()

查询当前运行环境网络信息

Returns

返回网卡信息

printerInfo

Array printerInfo()

查询当前主机的打印机信息

Returns

返回打印机信息

openPrinter

BufferedStream openPrinter(String name)

创建一个打印机输出对象

Parameters

  • name 打印机名称

Returns

返回打印机输出对象

platform

String platform()

查询当前平台名称,可能的结果为 ‘darwin’, ‘freebsd’, ‘linux’, 或 ‘win32’

time

Date time(String tmString)

解析时间字符串或查询运行环境当前时间

Parameters

  • tmString 时间字符串,缺省则查询当前时间

Returns

返回 javascript Date 对象

dateAdd

Date dateAdd(Date d,Integer num,String part)

时间计算函数,根据 part 指定计算时间

Parameters

  • d 指定用于计算 Date 对象

  • num 指定运算的数值

  • part 指定运算的时间部位,接收值为:”year”, “month”, “day”, “hour”, “minute”, “second”

Returns

返回 javascript Date 对象

memoryUsage

Object memoryUsage()

查询当前进程内存使用报告

Returns

返回包含内存报告

内存报告生成类似以下结果:

{
  "rss": 8622080,
  "heapTotal": 4083456,
  "heapUsed": 1621800,
  "nativeObjects": 122
}

其中:

  • rss 返回进程当前占用物理内存大小

  • heapTotal 返回 v8 引擎堆内存大小

  • heapUsed 返回 v8 引擎正在使用堆内存大小

  • nativeObjects 返回当前有效内置对象数