1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | // 加载 nodejs OS 模块 var os = global.require('os'); //通过调用 nodejs api,获取本地计算机的内存使用信息 var getMemoryData = function() { var fm = os.freemem(); var um = os.totalmem() - fm; return [ { x: "1", y: fm, text: "Free" }, { x: "1", y: um, text: "Used" } ]; } //通过调用 nodejs api,获取本地计算机的基本信息 var getSystemInfo = function() { return { hostname: os.hostname(), ostype: os.type(), platform: os.platform(), arch: os.arch(), cpus: os.cpus().length }; } |
1 2 3 4 5 6 7 8 9 10 11 | var fs = global.require('fs'); fs.readFile('/your/file.txt', function(err, data) { if (err) throw err; console.log(data); }); fs.writeFile('/your/file.txt', 'Hello World', function(err) { if (err) throw err; console.log('Saved!'); }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | request('http://www.ibm.com/developerworks/cn/views/global/rss/libraryview.jsp', { handleAs: 'xml' }).then(function(data){ var items = data.getElementsByTagName('item'); for (var i = 0; i < items.length; i++) { var item = items; var children = item.children; var title = children[0].textContent; var description = children[1].textContent; var link = children[2].textContent; var pubdate = new Date(Date.parse(children[3].textContent)); var feed = domConstruct.toDom([ '<div class="feed">', '<h4><a href="', link, '" target="_blank">', title, '</a></h4>', '<p>内容概要: ', description, '</p>', '<div>发布时间: ', locale.format(pubdate), '</div>', '</div>' ].join('')); dom.byId('feed-list').appendChild(feed); } }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | var net = require('net'); var client = net.connect({ port: 8088 }, function() { console.log('client connected'); client.write('hello world!\r\n'); //向服务器端发送 hello world! }); client.on('data', function(data) { console.log(data.toString()); //接受到服务器端发送来的数据 client.end(); }); client.on('end', function() { console.log('client disconnected'); }); |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |