【问题标题】:For some reason webserver won't listen由于某种原因,网络服务器不会听
【发布时间】: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

标签: node.js web server


【解决方案1】:

使用不同的端口号,如 3000、5000 等。

80端口被系统保留!

See details on wikipedia

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-12
    • 1970-01-01
    • 2021-08-05
    相关资源
    最近更新 更多