📜  Node.js 操作系统

📅  最后修改于: 2022-05-13 01:56:32             🧑  作者: Mango

Node.js 操作系统

OS 是一个节点模块,用于提供有关计算机操作系统的信息。
好处:
它提供与操作系统交互的功能。它提供操作系统的主机名并以字节为单位返回可用系统内存量。
示例 1:

javascript
// Include os module and create its object
var os = require('os');
  
// return the cpu architecture
console.log("CPU architecture: " + os.arch());
  
// It returns the amount of free system memory in bytes
console.log("Free memory: " + os.freemem());
  
// It return total amount of system memory in bytes
console.log("Total memory: " + os.totalmem());
  
// It returns the list of network interfaces
console.log('List of network Interfaces: ' + os.networkInterfaces());
  
// It returns the operating systems default directory for temp files.
console.log('OS default directory for temp files : ' + os.tmpdir ());


javascript
// Include os module and create its object
var os = require('os');
  
// return the endianness of system
console.log("Endianness of system: " + os.endianness());
  
// It returns hostname of system
console.log("Hostname: " + os.hostname());
  
// It return operating system name
console.log("Operating system name: " + os.type());
  
// It returns the platform of os
console.log('operating system platform: ' + os.platform());
  
// It returns the operating systems release.
console.log('OS release : ' + os.release());


输出:

示例 2:

javascript

// Include os module and create its object
var os = require('os');
  
// return the endianness of system
console.log("Endianness of system: " + os.endianness());
  
// It returns hostname of system
console.log("Hostname: " + os.hostname());
  
// It return operating system name
console.log("Operating system name: " + os.type());
  
// It returns the platform of os
console.log('operating system platform: ' + os.platform());
  
// It returns the operating systems release.
console.log('OS release : ' + os.release());

输出: