【问题标题】:I'm not able to start the mongo db server, getting the following error: [nodemon] app crashed - waiting for file changes before starting我无法启动 mongo db 服务器,出现以下错误:[nodemon] app crashed - waiting for file changes before waiting
【发布时间】:2022-02-09 02:28:30
【问题描述】:

这是 server.js 和 .env 文件 我正在尝试启动服务器,但它抛出了一个错误。

server.js

 const express = require('express');
 const cors = require('cors');
 const mongoose = require('mongoose');

 require('dotenv').config();

 const app = express();
 const port = process.env.PORT || 5000;

 app.use(cors());
 app.use(express.json());

 const uri = process.env.ATLAS_URI;
 mongoose.connect(uri, { useNewUrlParser: true, useCreateIndex: true });

 const connection = mongoose.connection;
 connection.once('open',() => {
     console.log("MongoDB database connection established successfully");
 })
 app.listen(port, () => {
     console.log(`Server is running on port: ${port}`);
 })
 

.env

ATLAS_URI = mongodb+srv://rnvsri:vastav123@cluster0.dgnw1.mongodb.net/test?retryWrites=true&w=majority 

问题:

在 cmd 中,我给出命令 nodemon server.js

但是服务器没有启动并且抛出以下错误。

nodemon] app crashed - waiting for file changes before starting...
[nodemon] restarting due to changes...
[nodemon] starting `node server.js`
node:events:368
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use :::5000
    at Server.setupListenHandle [as _listen2] (node:net:1334:16)
    at listenInCluster (node:net:1382:12)
    at Server.listen (node:net:1469:7)
    at Function.listen (/Users/rnvsrivastava/mern/restaurant-reviews/backend/backend/node_modules/express/lib/application.js:618:24)
    at Object.<anonymous> (/Users/rnvsrivastava/mern/restaurant-reviews/backend/backend/server.js:20:6)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1361:8)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'EADDRINUSE',
  errno: -48,
  syscall: 'listen',
  address: '::',
  port: 5000
}
[nodemon] app crashed - waiting for file changes before starting...

有人可以帮忙吗?

【问题讨论】:

  • 您的端口 (5000) 已在使用中。将端口更改为其他端口或终止端口

标签: node.js reactjs mongodb mongoose


【解决方案1】:

您正在使用的端口被另一个进程使用,您可以通过以下方式找到它 命令 lsof -i :PORT 并且可以使用 kill 命令杀死

kill PID

【讨论】:

    猜你喜欢
    • 2019-11-07
    • 2021-11-08
    • 2019-07-13
    • 1970-01-01
    • 2011-04-17
    • 1970-01-01
    • 2018-01-05
    • 2015-03-29
    • 2016-05-27
    相关资源
    最近更新 更多