Node.js OS module
Node.js OS module
Node.js os module provides some basic system operations functions. We incorporated the following modules:
var os = require("os")
method
No. | Method & description |
---|---|
1 | os.tmpdir () Returns the operating system's default temporary folder. |
2 | os.endianness () Returns CPU endian, it is possible that "BE" or "LE". |
3 | os.hostname () Returns the operating system's hostname. |
4 | os.type () Returns the operating system name |
5 | os.platform () Returns the operating system name |
6 | os.arch () Returns the operating system CPU architecture, the possible values are "x64", "arm" and "ia32". |
7 | os.release () Returns the release version of the operating system. |
8 | os.uptime () Returns the operating system running on time, in seconds. |
9 | os.loadavg () 1,5,15-minute average returns an array containing the load. |
10 | os.totalmem () Returns the total amount of system memory, in bytes. |
11 | os.freemem () It returns the amount of free memory operating system, in bytes. |
12 | os.cpus () Returns an array of objects, each containing the installed CPU / core information: type, speed (in MHz), time (contains user, nice, sys, idle, and irq the target CPU / core number of milliseconds use). |
13 | os.networkInterfaces () Obtain list of network interfaces. |
Attributes
No. | Property & Description |
---|---|
1 | os.EOL It defines the operating system of the end of line character constants. |
Examples
Create main.js file, the code is as follows:
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.");
Code execution results are as follows:
$ node main.js endianness : LE type : Linux platform : linux total memory : 25103400960 bytes. free memory : 20676710400 bytes.