这是创建 http 服务器的基本 Node js 代码。
const http = require("https");
const myServer = http.createServer((req, res) => {
console.log("New Req rec.");
res.end("Hellow from server");
});
myServer.listen(3000,()=> console.log("Server Started!"));
上面应该在 localhost 3000 显示“来自服务器的 Hellow”,但它显示“localhost 没有发送任何数据”。怎么解决这个问题。
您导入了错误的包。将包 https 替换为 http。
const http = require("http");
const myServer = http.createServer((req, res) => {
res.end("Hello from server");
});
myServer.listen(3000,()=> console.log("Server Started!"));