Search code examples
node.jsexpressnodemon

nodemon app crashed - waiting for file changes before starting...........mongodb


I have this problem after I connect my file app.js with mongo database. when I use the command npm run watch or nodemon app it works for a second then that happens: a

and this happened after I wrote this lines of code: b I tried to connect with new mongoDB account ..and it's the same


Solution

  • That's because you are trying ot listen for connections on a port that is already in use. EADDRINUSE.

    Before mongoose.connect() line, you are listening for connections on port 300 with app.listen(port).

    Then after handling the promise success .then(), you are doing the same, also listening for connections on the same port 300 with app.listen(port).

    Solution:

    Remove app.listen(port) line before // for DB comment.