1. 程式人生 > >node總結之工具模組(OS 模組)

node總結之工具模組(OS 模組)

Node.js os 模組提供了一些基本的系統操作函式,來看下引入該模組的語法格式:

var os = require("os")

來看下其中包含的方法:

序號 方法 & 描述
1 os.tmpdir()
返回作業系統的預設臨時資料夾。
2 os.endianness()
返回 CPU 的位元組序,可能的是 "BE" 或 "LE"。
3 os.hostname()
返回作業系統的主機名。
4 os.type()

返回作業系統名
5 os.platform()
返回作業系統名
6 os.arch()
返回作業系統 CPU 架構,可能的值有 "x64"、"arm" 和 "ia32"。
7 os.release()
返回作業系統的發行版本。
8 os.uptime()
返回作業系統執行的時間,以秒為單位。
9 os.loadavg()
返回一個包含 1、5、15 分鐘平均負載的陣列。
10 os.totalmem()

返回系統記憶體總量,單位為位元組。
11 os.freemem()
返回作業系統空閒記憶體量,單位是位元組。
12 os.cpus()
返回一個物件陣列,包含所安裝的每個 CPU/核心的資訊:型號、速度(單位 MHz)、時間(一個包含 user、nice、sys、idle 和 irq 所使用 CPU/核心毫秒數的物件)。
13 os.networkInterfaces()
獲得網路介面列表。

屬性如下 :

序號 屬性 & 描述
1 os.EOL
定義了作業系統的行尾符的常量。

來看下例項:

var os = require("os");

// CPU 的位元組序
console.log('endianness : ' + os.endianness());

// 作業系統名
console.log('type : ' + os.type());

// 作業系統名
console.log('platform : ' + os.platform());

// 系統記憶體總量
console.log('total memory : ' + os.totalmem() + " bytes.");

// 作業系統空閒記憶體量
console.log('free memory : ' + os.freemem() + " bytes.");

好啦,本次記錄就到這裡了。

如果感覺不錯的話,請多多點贊支援哦。。。