一、创建一个hellowrold.js文件。
使用 http.createServer() 方法创建服务器,并使用 listen 方法绑定 8888 端口。 函数通过 request, response 参数来接收和响应数据。
var http = require('http');
http.createServer(function (request, response) {
// 发送 HTTP 头部
// HTTP 状态值: 200 : OK
// 内容类型: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});
// 发送响应数据 "Hello World"
response.end('Hello World\n');
}).listen(8888);
// 终端打印如下信息
console.log('Server running at http://127.0.0.1:8888/');
二、运行这个js文件
在这个文件的目录下摁住shift 鼠标右击选择在此窗口打开shell命令
输入命令:node helloworld.js
三、在浏览器打开 127.0.1.1:8888这个网址。