创建web服务器
web服务器
使用javascript代码创建web服务
web服务 提供通过浏览器访问网络资源这种服务,web服务 以前通过web服务软件如nginx实现
通过nodejs提供的http模块实现web服务
1.安装nodejs环境
2. 引入http模块 let http = require('http) http.createServer()
const http = require('http')
//引入http模块
const server = http.createServer(function (request, response) {
//request 请求 //response 响应
response.writeHead(200,{'content-type':'text/html;charset=utf-8'})
//解决中文乱码
response.write('hello world nodejs 这是我响应的内容')
//写入内容到响应对象response
response.end()
//写入内容到响应对象
server.listen(3000, ()=> console.log('web服务启动成功,监听 3000端...'));
//启动web服务