 
- Node.js 教程
- Node.js - 主页
- Node.js - 简介
- Node.js - 环境设置
- Node.js - 第一个应用程序
- Node.js - REPL 终端
- Node.js - 包管理器 (NPM)
- Node.js - 回调概念
- Node.js - 事件循环
- Node.js - 事件发射器
- Node.js - 缓冲区
- Node.js - 流
- Node.js - 文件系统
- Node.js - 全局对象
- Node.js - 实用模块
- Node.js - Web 模块
- Node.js - Express 框架
- Node.js - RESTFul API
- Node.js - 扩展应用程序
- Node.js - 打包
- Node.js - 内置模块
- Node.js 有用资源
- Node.js - 快速指南
- Node.js - 有用的资源
- Node.js - 讨论
Node.js - OS Module
Node.js os module provides a few basic operating-system related utility functions. This module can be imported using the following syntax.
var os = require("os")
Methods
| Sr.No. | Method & Description | 
|---|---|
| 1 | os.tmpdir() Returns the operating system's default directory for temp files. | 
| 2 | os.endianness() Returns the endianness of the CPU. Possible values are "BE" or "LE". | 
| 3 | os.hostname() Returns the hostname of the operating system. | 
| 4 | os.type() Returns the operating system name. | 
| 5 | os.platform() Returns the operating system platform. | 
| 6 | os.arch() Returns the operating system CPU architecture. Possible values are "x64", "arm" and "ia32". | 
| 7 | os.release() Returns the operating system release. | 
| 8 | os.uptime() Returns the system uptime in seconds. | 
| 9 | os.loadavg() Returns an array containing the 1, 5, and 15 minute load averages. | 
| 10 | os.totalmem() Returns the total amount of system memory in bytes. | 
| 11 | os.freemem() Returns the amount of free system memory in bytes. | 
| 12 | os.cpus() Returns an array of objects containing information about each CPU/core installed: model, speed (in MHz), and times (an object containing the number of milliseconds the CPU/core spent in: user, nice, sys, idle, and irq). | 
| 13 | os.networkInterfaces() Get a list of network interfaces. | 
Properties
| Sr.No. | Property & Description | 
|---|---|
| 1 | os.EOL A constant defining the appropriate End-of-line marker for the operating system. | 
Example
The following example demonstrates a few OS methods. Create a js file named main.js with the following code.
var os = require("os");
// Endianness
console.log('endianness : ' + os.endianness());
// OS type
console.log('type : ' + os.type());
// OS platform
console.log('platform : ' + os.platform());
// Total system memory
console.log('total memory : ' + os.totalmem() + " bytes.");
// Total free memory
console.log('free memory : ' + os.freemem() + " bytes.");
Now run the main.js to see the result −
$ node main.js
Verify the Output.
endianness : LE type : Linux platform : linux total memory : 25103400960 bytes. free memory : 20676710400 bytes.
