zi663227 发表于 2017-2-21 10:35:56

nodejs http服务

  创建server.js文件(最好保存为utf-8格式,这样避免中文乱码)
  


var http = require('http');
var port = 1337;
var httpServer = http.createServer(onRequest).listen(port);
function onRequest(req, res) {
res.writeHead(200, {"Content-Type": "text/plain"});
res.write("Hello World 你好",'utf8');
res.end();
}
console.info('Server running at http://127.0.0.1:1337/');
  输入命令:node workspace/server.js
  

  在浏览器输入http://localhost:1337/
  
页: [1]
查看完整版本: nodejs http服务