Module basic module

Module os

Operating system and file system processing module

Instructions:

1
var os = require('os');

Object

Service

Service constructor, see Service

1
Service os.Service;

Static function

hostname

Query the host name of the current running environment

1
static String os.hostname();

Return result:

  • String , returns the host name

endianness

Query the byte order of the current CPU

1
static String os.endianness();

Return result:

  • String , return byte order

type

Query the operating system name of the current running environment

1
static String os.type();

Return result:

  • String , returns the system name

release

Query the operating system version of the current operating environment

1
static String os.release();

Return result:

  • String , return version information

homedir

Query current user directory

1
static String os.homedir();

Return result:

  • String , returns the directory string

arch

Query the current cpu environment

1
static String os.arch();

Return result:

  • String , returns the cpu type, possible results are'amd64','arm','arm64','ia32'

uptime

Query the running time of the running environment, in seconds

1
static Number os.uptime();

Return result:

  • Number , returns a numeric value representing the time

loadavg

Query the operating environment for 1 minute, 5 minutes, 15 minutes average load

1
static Array os.loadavg();

Return result:

  • Array , returns an array containing three load data

totalmem

Query the total memory of the operating environment, in bytes

1
static Long os.totalmem();

Return result:

  • Long , return memory data

freemem

Query the available memory of the operating environment, in bytes

1
static Long os.freemem();

Return result:

  • Long , return memory data

cpus

Query the number and parameters of the current operating environment cpu

1
static Array os.cpus();

Return result:

  • Array , returns an array containing cpu parameters, each item corresponds to a cpu

cpuNumbers

Query the number of CPUs in the current operating environment

1
static Integer os.cpuNumbers();

Return result:

  • Integer , returns the number of cpu

tmpdir

Query the temporary file directory of the current operating environment

1
static String os.tmpdir();

Return result:

  • String , returns the temporary file directory

userInfo

Return the current effective user information

1
static Object os.userInfo(Object options = {});

Call parameters:

  • options : Object, the character encoding used to interpret the result string

Return result:

  • Object , current effective execution user information

networkInterfaces

Query current operating environment network information

1
static Object os.networkInterfaces();

Return result:

  • Object , return network card information

printerInfo

Query the printer information of the current host

1
static Array os.printerInfo();

Return result:

  • Array , return printer information

openPrinter

Create a printer output object

1
static BufferedStream os.openPrinter(String name) async;

Call parameters:

  • name : String, printer name

Return result:


platform

Query the current platform name

1
static String os.platform();

Return result:

  • String , returns the platform name, possible results are'darwin','freebsd','linux', or'win32'

time

Parse the time string or query the current time of the runtime environment

1
static Date os.time(String tmString = "");

Call parameters:

  • tmString : String, time string, the default is to query the current time

Return result:

  • Date , returns the javascript Date object

dateAdd

Time calculation function, specify calculation time according to part

1 2 3
static Date os.dateAdd(Date d, Integer num, String part);

Call parameters:

  • d : Date, specified for calculating Date objects
  • num : Integer, specify the value of the operation
  • part : String, specify the time part of the operation, the accepted values ​​are: "year", "month", "day", "hour", "minute", "second"

Return result:

  • Date , returns the javascript Date object

memoryUsage

Query current process memory usage report

1
static Object os.memoryUsage();

Return result:

  • Object , return contains memory report

The memory report generates results similar to the following:

1 2 3 4 5 6
{ "rss": 8622080, "heapTotal": 4083456, "heapUsed": 1621800, "nativeObjects": 122 }

among them:

  • rss returns the size of physical memory currently occupied by the process
  • heapTotal returns the v8 engine heap memory size
  • heapUsed returns the size of the heap memory being used by the v8 engine
  • nativeObjects returns the current number of valid built-in objects

Static properties

timezone

Integer, query the current time zone of the runtime environment

1
static readonly Integer os.timezone;

EOL

String, query the end of line identifier of the current operating environment, posix:\"\n\"; windows:\"\r\n\"

1
static readonly String os.EOL;

execPath

String, query the full path of the current execution file

1
static readonly String os.execPath;