Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Node .js system


May 10, 2021 Node.js


Table of contents


System

稳定性: 4 - API 冻结

The node .js (OS) module provides some functions related to the basic operating system.

Access require('os') as follows:

const os = require('os');

os.tmpdir()

The default temporary folder used to return the operating system.

os.endianness()

The byte order used to return the CPU, possibly "BE" or "LE".

os.hostname()

The host name used to return the operating system.

os.type()

Used to return the operating system name.

os.platform()

Used to return the operating system name

os.arch()

Used to return the operating system CPU schema, possible values are "x64," "arm," and "ia32."

os.release()

Used to return the release version of the operating system

os.uptime()

Used to return the time, in seconds, that the operating system ran.

os.loadavg()

The other translation correction used to display the original returns an array with an average load of 1, 5, and 15 minutes.

The average load is an indicator of the system, calculated by the operating system, expressed in a very small number. T heoretically, the average load is preferably lower than the CPU in the system.

Average load is a very UNIX-y concept, and windows systems don't have the same concept. So windows always [0, 0, 0]

os.totalmem()

Used to return the total amount of system memory in bytes.

os.freemem()

Used to return the amount of operating system free memory in bytes.

os.cpus()

Used to return an array of objects that contain information for each CPU/core installed: model number, speed (in MHz), time (an object that contains cpu/core milliseconds used by user, nice, sys, idle, and irq).

Examples of os.cpus:

[ { model: 'Intel(R) Core(TM) i7 CPU         860  @ 2.80GHz',
    speed: 2926,
    times:
     { user: 252020,
       nice: 0,
       sys: 30340,
       idle: 1070356870,
       irq: 0 } },
  { model: 'Intel(R) Core(TM) i7 CPU         860  @ 2.80GHz',
    speed: 2926,
    times:
     { user: 306960,
       nice: 0,
       sys: 26980,
       idle: 1071569080,
       irq: 0 } },
  { model: 'Intel(R) Core(TM) i7 CPU         860  @ 2.80GHz',
    speed: 2926,
    times:
     { user: 248450,
       nice: 0,
       sys: 21750,
       idle: 1070919370,
       irq: 0 } },
  { model: 'Intel(R) Core(TM) i7 CPU         860  @ 2.80GHz',
    speed: 2926,
    times:
     { user: 256880,
       nice: 0,
       sys: 19430,
       idle: 1070905480,
       irq: 20 } },
  { model: 'Intel(R) Core(TM) i7 CPU         860  @ 2.80GHz',
    speed: 2926,
    times:
     { user: 511580,
       nice: 20,
       sys: 40900,
       idle: 1070842510,
       irq: 0 } },
  { model: 'Intel(R) Core(TM) i7 CPU         860  @ 2.80GHz',
    speed: 2926,
    times:
     { user: 291660,
       nice: 0,
       sys: 34360,
       idle: 1070888000,
       irq: 10 } },
  { model: 'Intel(R) Core(TM) i7 CPU         860  @ 2.80GHz',
    speed: 2926,
    times:
     { user: 308260,
       nice: 0,
       sys: 55410,
       idle: 1071129970,
       irq: 880 } },
  { model: 'Intel(R) Core(TM) i7 CPU         860  @ 2.80GHz',
    speed: 2926,
    times:
     { user: 266450,
       nice: 1480,
       sys: 34920,
       idle: 1072572010,
       irq: 30 } } ]

os.networkInterfaces()

Here's how to get a list of network interfaces:

{ lo:
   [ { address: '127.0.0.1',
       netmask: '255.0.0.0',
       family: 'IPv4',
       mac: '00:00:00:00:00:00',
       internal: true },
     { address: '::1',
       netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
       family: 'IPv6',
       mac: '00:00:00:00:00:00',
       internal: true } ],
  eth0:
   [ { address: '192.168.1.108',
       netmask: '255.255.255.0',
       family: 'IPv4',
       mac: '01:02:03:0a:0b:0c',
       internal: false },
     { address: 'fe80::a00:27ff:fe4e:66a1',
       netmask: 'ffff:ffff:ffff:ffff::',
       family: 'IPv6',
       mac: '01:02:03:0a:0b:0c',
       internal: false } ] }

os. Eol

Defines the constant of end-of-line for the operating system.