Search code examples
javascriptnode.jsnodemon

Nodemon crashes and shows waiting for file changes


I am using nodemon version 1.18.3 and express version 4. Upon running nodemon command directly, I get the following error:

events.js:165
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE :::3000
    at Server.setupListenHandle [as _listen2] (net.js:1346:14)
    at listenInCluster (net.js:1387:12)
    at Server.listen (net.js:1475:7)
    at Function.app.listen (/home/rishabh/Documents/my_projects/getting_MEAN/loc8r/node_modules/express/lib/application.js:531:24)
    at Object.<anonymous> (/home/rishabh/Documents/my_projects/getting_MEAN/loc8r/bin/www:7:18)
    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)
Emitted 'error' event at:
    at emitErrorNT (net.js:1366:8)
    at process._tickCallback (internal/process/next_tick.js:178:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:697:11)
    at startup (internal/bootstrap/node.js:201:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)
[nodemon] app crashed - waiting for file changes before starting...

Nodemon crashes and keeps on waiting for file changes.


Solution

  • This is happening because nodemon can't watch your file system as mentioned in this issue on github.

    Basically, there's something known as inotify watchers which nodemon uses to watch the changes that you do in your code.

    You can fix this by increasing the amount of max watchers and then restart your computer to apply the changes:

    echo fs.inotify.max_user_watches=524298 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
    

    It's also mentioned here.

    or you can also add the following code in your endpoint file:

    process.on('SIGUSR2', () => { process.exit(0); });