nodejs第一个练习:用Node.js建HTTP服务器

这是官方的一个例子,

在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 http://127.0.0.1:1337/');

在F盘下运行node tinyphp.js

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

需要提示的是,命令完,需要按Ctrl+C才能重新写命令的

posted @ 2015-10-29 21:40  tinyphp  Views(363)  Comments(0Edit  收藏  举报