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,
After loading os module you can use it to display operating system temp directory as below,
You can access host name as following,
You can access total memory and free memory as below,
You can access OS type and platform as below,
You can fetch CPU information as below,
Node will return output as below,
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.
沒有留言:
張貼留言