2014年10月8日 星期三

Working with OS Module in Node.JS

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,
1
2
3
4
5
6
7
8
9
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.

沒有留言:

張貼留言