/**
* Created by liangshuang on 17/11/21.
监听端口:1337
监听到1337服务器过来的请求后,就会执行匿名的回调函数即下面的function
req:请求体 res:响应体
*/
var http = require('http');
var server = http.createServer(function (req, res) {
res.writeHead(200, {'content-Type':'text/plain'});
res.end('Hello world ');
});
server.listen(1337,'127.0.1');
console.log('Server running at http://127.0.1:1337/');
在终端运行:
➜ ~ cd /wwwroot/node
➜ node ls
beginning
➜ node cd beginning
➜ beginning
➜ beginning ls
server.js
➜ beginning node server.js
再在浏览器输入127.0.1:1337即可