node.js学习笔记(11) os-阿里云开发者社区

开发者社区> 云计算> 正文

node.js学习笔记(11) os

简介:

Node.js提供了一些基本的底层操作系统的信息,可通过os模块获取。


eg:  os-info.js


var os = require('os');

console.log('arch:'+os.arch());
console.log('cpus:'+JSON.stringify(os.cpus()));
console.log('endianness:'+os.endianness());
console.log('freememory:'+os.freemem());
console.log('home directory:'+os.homedir());
console.log('hostname:'+os.hostname());
console.log('loadavg:'+os.loadavg());
console.log('networkInterfaces:'+JSON.stringify(os.networkInterfaces()));
console.log('platform:'+os.platform());
console.log('release:'+os.release());
console.log('tmpdir:'+os.tmpdir());
console.log('total memory:'+os.totalmem());
console.log('os type:'+os.type());
console.log('uptime:'+os.uptime());


运行效果:


lee@mypc ~/works/nodejs/study11 $ node os-info.js 
arch:x64
cpus:[{"model":"Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz","speed":1734,"times":{"user":149886100,"nice":147800,"sys":39271600,"idle":2031713300,"irq":8000}},{"model":"Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz","speed":2802,"times":{"user":131681000,"nice":79200,"sys":28948300,"idle":374590600,"irq":0}},{"model":"Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz","speed":2607,"times":{"user":151929700,"nice":232000,"sys":35666800,"idle":368223400,"irq":400}},{"model":"Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz","speed":1058,"times":{"user":130426600,"nice":81400,"sys":28682800,"idle":375297700,"irq":0}}]
endianness:LE
freememory:3970260992
home directory:/home/lee
hostname:lee-ThinkPad-X220
loadavg:0.25244140625,0.30859375,0.31494140625
networkInterfaces:{"lo":[{"address":"127.0.0.1","netmask":"255.0.0.0","family":"IPv4","mac":"00:00:00:00:00:00","internal":true},{"address":"::1","netmask":"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff","family":"IPv6","mac":"00:00:00:00:00:00","scopeid":0,"internal":true}],"wlan0":[{"address":"192.168.6.45","netmask":"255.255.255.0","family":"IPv4","mac":"10:0b:a9:bd:7c:a4","internal":false},{"address":"fe80::120b:a9ff:febd:7ca4","netmask":"ffff:ffff:ffff:ffff::","family":"IPv6","mac":"10:0b:a9:bd:7c:a4","scopeid":3,"internal":false}]}
platform:linux
release:3.16.0-38-generic
tmpdir:/tmp
total memory:8249782272
os type:Linux
uptime:731944


版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
云计算
使用钉钉扫一扫加入圈子
+ 订阅

时时分享云计算技术内容,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。

其他文章