您的位置:首页 > 理论基础 > 计算机网络

用Node.js建HTTP服务器

2015-10-29 21:40 525 查看
这是官方的一个例子,

在F盘建立一个tinyphp.js文件,内容:

var http = require('http');

http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "127.0.0.1");

console.log('Server running at ' target='_blank'>http://127.0.0.1:1337/');[/code] 
在F盘下运行node tinyphp.js



然后打开浏览器访问: http://127.0.0.1:1337


需要提示的是,命令完,需要按Ctrl+C才能重新写命令的
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: