The os module provides access to operating system information such as hostname, CPU details, and memory usage, including free system memory in bytes.
- os.arch(): Returns the CPU architecture (e.g., x64, arm).
- os.cpus(): Returns an array with details of each CPU/core.
- os.freemem(): Returns free system memory in bytes.
- os.homedir(): Returns the current user’s home directory path.
- os.hostname(): Returns the system hostname.
- os.networkInterfaces(): Returns network interface information.
- os.platform(): Returns the operating system platform (e.g., linux, darwin).
- os.release(): Returns the operating system release version.
- os.totalmem(): Returns total system memory in bytes.
- os.uptime(): Returns system uptime in seconds.
Features
The os module offers utilities to inspect system details, monitor resources, and detect the operating system platform.
- System Information: Provides insights into the system’s hardware and software environment.
- Resource Monitoring: Helps in monitoring memory usage and system performance.
- Platform Detection: Identifies the platform and version of the operating system.
Example: Uses Node.js os module to fetch and display system details and memory info.
Output:
👁 Image
Example: Displays system endianness, hostname, OS name, platform, and release using the Node.js os module.
Output:
👁 Image
Benefits
- Enhanced Functionality: Facilitates writing system-specific code.
- Performance: Allows monitoring and optimizing system resource usage.
- Cross-Platform Support: Ensures compatibility across different operating systems.
Also Check: