【发布时间】:2021-12-23 22:02:33
【问题描述】:
我有这个代码:
const express = require("express");
const app = express();
var meetings = [];
app.use("/static", express.static("public/"))
app.use("/index.html?", function(request, response, next) {
response.redirect("/");
})
app.get("/", function(request, response) {
response.sendFile(__dirname + "/pages/index.html");
})
try {
app.listen(80);
} catch(e) {
console.log("Can't run on port 80. Please, run me as a sudo!");
}
当我运行它时,我得到了这个错误:
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1361:8)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'EACCES',
errno: -13,
syscall: 'listen',
address: '0.0.0.0',
port: 80
}
Node.js v17.0.1
当我以 sudo 运行它时,它找不到 express 模块。 我做错了什么? 任何帮助表示赞赏。
【问题讨论】:
-
如果没有 root 用户,您无法在低于 1024 的端口上监听 - 它们在历史上是“特权端口”。
-
我要处理一个错误
-
你想处理哪个错误?
-
我要处理 EACCES 错误