Home » Node.js

Node OS Module

Node OS Module: In this tutorial, we are going to learn about the Node OS Module with its examples.
Submitted by Godwill Tetah, on June 02, 2019

Node modules are like libraries which help us perform specific tasks. Node.js is always considered powerful because it has a very large ecosystem of third-party modules.

The OS module is a built-in module used to get information about the computer's operating system and other important information about a system.

Take Note! You should have Node js in your PC.

With Node.js already up and running, let's get started.

Now, let's get started.

The OS module is an object where we make use of it's various properties to get the information we desire.

For example, os.arch() gives us the operating system CPU architecture.

Below, we'll see how to get information about the computer's free memory, platform, architecture and host name on the console.

Open a text editor and type the following code and save it with the file name app.js:

const os = require('os'); // include the OS module

console.log("Platform: " + os.platform());
console.log("Architecture: " + os.arch());
console.log (" Free memory: "  + os.freemem() );
console.log("Host name: " + os.hostname());

Note: The file should be saved in your default Node.js directory.

Run the code by initiating the file at the command prompt like a regular Node.js file.

Node OS module




Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.