Working with OS Module in Node.JS

In this post we will take a quick look on OS module in Node.js. OS module is to work with OS component. It provides some functionality to work with Operating System. Using this module you can get following information like below,

  • OS target version
  • Host name
  • OS temp folder
  • Total memory in system
  • Free memory in system
  • Load on system etc.

To work with os module you need to load the module first. You can load module as given below,

clip_image001

After loading os module you can use it to display operating system temp directory as below,

clip_image002

You can access host name as following,

clip_image003

You can access total memory and free memory as below,

clip_image004

You can access OS type and platform as below,

clip_image005

You can fetch CPU information as below,

clip_image006

Node will return output as below,

clip_image008

We saw that os module is very important to fetch information about operating system. Putting all together you can get various os information as below,


var os = require('os');
console.log(os.hostname());
console.log(os.totalmem());
console.log(os.freemem());
console.log(os.tmpdir());
console.log(os.uptime());
console.log(os.type());
console.log(os.platform());
console.log(os.cpus());

I hope you find this quick post on Node os module useful. Thanks for reading.

About these ads

3 thoughts on “Working with OS Module in Node.JS

  1. Hi sir,
    i m reading your post on node.js.. i had done all the steps which are required for executing the node files. i m able to run node files with command prompt but not able to understand that what is the procedure to execute these code in html files.. plz do the reply ASAP..
    tnx :)

  2. You have to write client if you are creating service on Node. Else use Express framework to create Node based web applications.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s