我试图运行我的节点服务器运行,但突然我有这个错误。我怎么能解决这个错误?当我命令npm运行start-dev显示我这个错误。我已经改变了这个端口,但得到了相同的错误。为什么发生这个错误?请帮助我,我怎么能解决这个问题?
这是错误,
node:events:491
throw er; // Unhandled 'error' event
^
Error: listen EACCES: permission denied 30000;
at Server.setupListenHandle [as _listen2] (node:net:1468:21)
at listenInCluster (node:net:1533:12)
at Server.listen (node:net:1632:5)
at Function.listen (D:\ecommerce-api\node_modules\express\lib\application.js:635:24)
at StartDB (D:\ecommerce-api\app.js:34:9)
at Object.<anonymous> (D:\ecommerce-api\app.js:42:1)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1512:8)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
code: 'EACCES',
errno: -4092,
syscall: 'listen',
address: '5000;',
port: -1
}
Node.js v18.12.1
[nodemon] app crashed - waiting for file changes before starting...
my env file
PORT=5000;
MONGO_URI=mongodb://127.0.0.1:27017/ecommerce
App js file
require("dotenv").config();
const express = require("express");
const app = express();
const port = process.env.PORT || 5000;
//Database
const connectDB = require("./DB/ConnectDB");
//Paths
const authRoute = require("./Routes/AuthRoute");
//Middleware
app.use(express.json());
app.get("/", (req, res) => {
res.send("Ecommerce API!");
});
app.use("/api/v1/auth", authRoute);
const StartDB = async () => {
try {
connectDB(process.env.MONGO_URI);
app.listen(port, () => {
console.log(`App listening on port ${port}`);
});
} catch (error) {
console.log(error);
}
};
StartDB();
下面的包json文件. my pacakge json file
{
"name": "ecommerce-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js",
"start-dev": "nodemon app.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"express-async-errors": "^3.1.1",
"http-status-codes": "^2.2.0",
"jsonwebtoken": "^9.0.0",
"mongoose": "^6.8.4",
"morgan": "^1.10.0",
"validator": "^13.7.0"
}
}
1条答案
按热度按时间5vf7fwbs1#
dotenv
不使用半克隆。如果您检查日志,您可以很容易地看到
address
被设置为5000;
和port
被设置为-1
由于不正确的输入值。从您的
.env
文件中删除semi克隆。如下所示