Core Modules
Node.js OS
Node.js OS Module
Node.js OS module provides system info like cpus and platform.
Introduction to the OS Module
The OS module in Node.js provides a wide array of operating system-related utility methods and properties. It allows developers to interact with the operating system to gather information like CPU architecture, network interfaces, uptime, and more. This module is particularly useful for applications that need to adapt based on the environment in which they are running.
Importing the OS Module
To begin using the OS module in your Node.js application, you need to import it using the require
function. The OS module is a core module, so no additional installation is necessary.
Getting System Information
One of the primary uses of the OS module is to retrieve information about the system. Below are some common methods:
os.cpus()
: Returns an array of objects containing information about each CPU/core installed, like model and speed.os.platform()
: Returns a string identifying the operating system platform.os.uptime()
: Returns the system uptime in seconds.