os 모듈은 운영체제의 정보를 얻어오는 매우 유용한 함수 세트를 제공한다.
다음 코드는 os 모듈의 각 함수를 호출한 결과이다.
var os = require('os');
console.log("tmpdir :\t" + os.tmpdir());
console.log("endianness :\t" + os.endianness());
console.log("hostname :\t" + os.hostname());
console.log("type :\t\t" + os.type());
console.log("platform :\t" + os.platform());
console.log("arch :\t\t" + os.arch());
console.log("release :\t" + os.release());
console.log("uptime :\t" + os.uptime());
console.log("loadavg :\t" + os.loadavg());
console.log("totalmem :\t" + os.totalmem());
console.log("freemem :\t" + os.freemem());
console.log("EOL :\t" + os.EOL);
console.log("cpus :\t\t" + JSON.stringify(os.cpus()));
console.log("networkInterfaces : " + JSON.stringify(os.networkInterfaces()));
아래는 출력결과 화면이다.
tmpdir : C:/Users/es-lko/AppData/Local/Temp
endianness : LE
hostname : es-lko-D
type : Windows_NT
platform : win32
arch : x64
release : 6.1.7601
uptime : 2841.3511742
loadavg : 0,0,0
totalmem : 8516907008
freemem : 4305489920
EOL :
cpus : [{"model":"Intel(R) Core(TM) i5-3570 CPU @ 3.40GHz","speed":3392
,"times":{"user":96533,"nice":0,"sys":146016,"idle":2601550,"irq":14352}},{"mode
l":"Intel(R) Core(TM) i5-3570 CPU @ 3.40GHz","speed":3392,"times":{"user":111493
,"nice":0,"sys":107515,"idle":2624654,"irq":1653}},{"model":"Intel(R) Core(TM) i
5-3570 CPU @ 3.40GHz","speed":3392,"times":{"user":103147,"nice":0,"sys":381094,
"idle":2359296,"irq":2433}},{"model":"Intel(R) Core(TM) i5-3570 CPU @ 3.40GHz","
speed":3392,"times":{"user":93538,"nice":0,"sys":230741,"idle":2519119,"irq":160
6}}]
networkInterfaces : {"로컬 영역 연결":[{"address":"fe80::b4cf:5523:edea:5299","f
amily":"IPv6","internal":false},{"address":"10.5.2.146","family":"IPv4","interna
l":false}],"Loopback Pseudo-Interface 1":[{"address":"::1","family":"IPv6","inte
rnal":true},{"address":"127.0.0.1","family":"IPv4","internal":true}]}