废话不多说,直接上代码
const http = require('http');
// 1、创建一个httpserver服务
http.createServer(function(request,response){
//这是请求头
//response.writeHead(200,{'Content-type':'text/html'});
//结果的内容
//response.end("<div>123</div>")
}).listen(8080);// 服务端口号
console.log("您启动的服务是http://localhost:8888")
nodejs 是一个服务端语言
上面这段代码只有一点需要注意,引用模块的时候必须用require(),按照eslink的提示改成es6的import反而是错误的。不要写顺手喽
参考网站
http://nodejs.cn/api/synopsis.html nodejs的中文api
网友评论