The os module gives a few basic operating system related utility functions. OS 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
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.");
$ node main.js
Output
endianness : LE type : Linux platform : linux total memory : 25103400960 bytes. free memory : 20676710400 bytes.
Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.