Nodejs OS module :
os module provides a couple of different utility methods and properties related to the operating system. It is an useful module if you want to make sure that your program will work on all different operating systems.
In this blog post, we are listing down all different constants and methods you can access using the os module.
How to use this module :
You need to import this module if you want to access its methods :
const os = require('os')
Properties :
os.EOL :
It returns the end-of-line marker. This value is operating system specific.
Constants :
You can receive different types of OS related constants in Nodejs :
-
os.constants.signals: signal constants
-
os.constants.errno: Error constants
-
os.constants.dlopen: dlopen constants
-
os.constants.priority: priority constants
Few more constants are available in Nodejs. You can check here to learn more on it.
Methods :
1. os.arch():
Get the architecture of the OS.
os.cpus():
Get all CPUs in the OS.
os.endianness():
Get the endianness of the CPU.
os.freemem():
Get the amount of free memory in bytes.
os.getPriority([pid]):
Scheduling priority of the process with process id pid.
os.homedir():
Get the home directory.
os.hostname():
Get the hostname of the home directory.
os.loadavg():
Get 1, 5 and 15 minutes load average.
os.networkInterfaces():
Get the information of all network interfaces.
os.release():
Get the OS name.
os.platform():
Get the platform of the OS.
os.setPriority([pid, ]priority):
Set the scheduling priority of a process with id pid.
os.tmpdir():
Get the default temporary file directory for the current OS.
os.totalmem():
Get the total memory in bytes.
os.type():
Get the OS name.
os.uptime():
Get the system uptime seconds.
os.userInfo([options]):
Get the information on the current effective user.
That’s all. You can go through the link provided above to learn in detail.