您的位置:首页 > Web前端 > Node.js

node.js入门示例

2016-01-16 15:36 579 查看
1、控制台版 Hello World

编辑文件hello_world.js

var sys = require("util");
sys.puts("Hello world");


执行:node hello_world.js

结果:


2、网页版Hello world

编译文件 http_hello_world.js

var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World - Node.js Work.
');
}).listen(5656, '127.0.0.1');
console.log('Server running at ' target='_blank'>http://127.0.0.1:5656/');[/code] 执行: node http_hello_world.js

结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: