1,编写代码
2,运行服务器
3,源码地址
1,编写代码
创建一个js文件,名字为01hello.js,编写代码
/**
* Created by boy on 2017/7/10.
*/
//1,引用http
var http = require("http");
//2,创建Server对象,并且监听。
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);
// 3,终端打印如下信息
console.log('Server running at http://localhost:8888/');
2,运行服务器
(1)进入项目目录
(2)运行nodejs。
(3)在浏览器输入http://localhost:8888/,如果出现hello world信息就成功。