Hello world 入门示例
新建server.js,并编写代码:
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8023);
console.log('Server running at http://127.0.0.1:8023/');
运行server.js文件,开启服务:
$~ node server.js
$~ Server running at http://127.0.0.1:8023/
最后打开任意浏览器打开这个地址:http://127.0.0.1:8023/ ,就可以看到Hello World
字样.