-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
21 lines (21 loc) · 709 Bytes
/
server.js
File metadata and controls
21 lines (21 loc) · 709 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
var http = require('http');
var os = require('os');
var url = require('url');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
var call = url.parse(req.url).pathname.replace(/.*\/|\.[^.]*$/g, '');
if( call === "all"){
Object.keys(os).map(function(method) { res.write(method+":"+JSON.stringify(os[method](),2,true))+","; })
}
else{
try{
var resu = os[call]();
res.write(JSON.stringify(resu),'utf8');
}
catch(e){
res.end("Sorry, try on of : "+Object.keys(os).join(", "));
}
}
res.end();
}).listen(process.env.port || 1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');