【发布时间】:2021-08-23 21:23:19
【问题描述】:
所以我在 webServer 文件夹中有 webServer.js 和 package.json,由于某种原因,当我在 cmd 中使用节点 webServer.js 调用它时,webserver 不会监听
这是我的网络服务器
var http = require('http');
http.createServer(function(req, res){
console.log(req);
console.log("***********************************");
console.log("***********************************");
console.log("***********************************");
console.log("***********************************");
console.log("***********************************");
console.log("***********************************");
console.log("***********************************");
console.log("***********************************");
console.log("***********************************");
console.log(req.url);
res.writeHead(200, {'Content-Type' : 'text/html'});
res.write('hello world');
res.end();
}).listen(80);
这是 package.json
{
"name": "webserver",
"version": "1.0.0",
"description": "",
"main": "webSever.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
这是我输入 cmd node webServer.js:https://imgur.com/a/p2iK3r4 时得到的结果
这就是我在浏览器中键入 localhost/80 时发生的情况 无限加载:https://imgur.com/KQhtqlW
【问题讨论】:
-
应该是
localhost:80或只是localhost,而不是localhost/80