2. 建立一个简单的服务器

2019-05-26  本文已影响0人  论宅

新建一个esayhttp.js,填上基本的内容:

var http = require('http');
http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<h1>Node.js</h1>');
res.end('<p>Hello World</p>');
}).listen(3000);
console.log("HTTP server is listening at port 3000.");

使用命令:

git node easyhttp.js

启动服务器
打开浏览器,打开localhost:3000
便可以看到结果

上一篇下一篇

猜你喜欢

热点阅读