13

I've recently reinstalled node package manager npm install nodemon -g which grabbed the latest build. But when I run nodemon server.js and I save changes to files, it's extremely slow to restart the server. It might take 10-30 seconds to detect file changes and when the restart process executes, it can take a few seconds to finish. I'm using nodemon 1.17.3. I don't have this problem on my other build (same PC and same local parent directory) that's using nodemon 1.14.8. Has anyone else experienced this?

chasnz
  • 179
  • 1
  • 6

1 Answers1

3

There can be several reasons for the slow server restart. Here are few things you can try

Exclude unnecessary files which doesnt require monitoring from nodemon Create a nodemon.config.js file and add the files you dont want nodemon to check while restarting the server ex:

{
  "ignore": [
    "node_modules",
    "public"
  ]
}

Or to check only the changed files you can specify nodemon which files to monitor while restarting the server by --watch flag

nodemon --watch src/user.model.js

You can also increase the amount of memory available to Node. If your server is slow due to memory limitations you can make the maximum amount of memory availbale (in megabites) by

nodemon --max-old-space-size=4096 app.js

I hope this helps.