HTTP(Ⅱ)—— 用node创建一个简单的WEB服务

我们首先安装node.js。用git bash查看node是否安装好,用node -v查看一下node 版本即可。

编写一个简单的web服务,取名server.js

const http = require('http')
http.createServer(function(request, response) {
	console.log('request come', request.url)
	response.end('123')
}).listen(8888)
console.log('server listening on 8888')

在git bash里面启动一下,使用命令node server.js。如果成功会显示server listening on 8888。

然后打开浏览器,输入localhost:8888会显示出123。这就是一个简单的web服务。

猜你喜欢

转载自blog.csdn.net/zhanghuali0210/article/details/82078726