http创建web server官网:
https://nodejs.org/api/http.html#http_class_http_server
刚开始,是要在electron中使用node,创建本地服务器
首先要有个server.js
const http = require('http');
//const hostname = '127.0.0.1'; //可以不写,或者写localhost
const port = 7888;
// 通过 createServer 创建 web服务器
const server = http.createServer((req, res) => {
//req 请求体:获取请求相关的信息(请求来自哪里、是get还是post)
//res 响应体:告诉服务器给请求响应什么内容
console.log('req'+req,'res'+res+'server.js-------14行')
// 设置响应的请求头状态码是200
res.statusCode = 200;
// 设置返回的文本类型:纯文本text/plain
res.setHeader('Content-Type', 'application/json'); //序列化后的 JSON 字符串
// 最后给客户端返回 hello world
res.end('Hello World!\n'+res+'server.js-----20');
});
// 处理请求, request与click事件一致, 有请求就会触发re