http爬虫 + http web服务器渲染数据发送前台 + 中文乱码
服务器:
可以运行在服务端一个网站(站点)
种类:
- web服务器( 静态服务器 ) ,可以运行在浏览器中的服务器
- api服务器 ( 后端接口 ) 后端语言暴露一个数据接口,用于前端数据请求( ajax fetch )
Node.js中原生创建web服务器
http模块
createServer( callback ) 创建服务器
callback中接收三个参数 request response
listen(port,host,callback) 监听服务器( 反馈服务器状态 )
port 端口
host 域名
// 1.引入http模块
const http = require('http');
//2.定义端口和域名
const port = 8888;
const host = 'localhost' //127.0.0.1
//3.通过http模块的createServer api可以创建一个web服务器
const server = http.createServer((request, Response) => {
Response.writeHead(200, {
'content-type': 'text/html;charset=UTF8' //设置反馈头信息
})
Response.write('<h1>hello world 你好</h1>') //向前台发送数据
Response.e