Home > Enterprise >  Prevent nodemon from restarting due to changes to a json-file
Prevent nodemon from restarting due to changes to a json-file

Time:11-24

I have a nodemon server running, but if I change a file with fs.writeFileSync nodemon restarts and the json-file loses its data.

I tried to prevent this by putting a ignore in the package.json

"nodemonConfig": {
  "ignore": ["*.json"]
}

This is not working. I think it could be because I installed nodemon global. Then I found another possibility to prevent this by creating a nodemon.json with:

{
    "ignore": ["*.json"]
}

but this is also not working. The third possibility was to write:

nodemon --ignore '[users.json]'

in the terminal. It could be that I wrote the line wrong or something else, but I am just not getting the solution for this problem.

CodePudding user response:

You can add nodemon configuration within the package.json file, for example:

{
  "name": "label",
  "version": "0.0.1",
     

  "nodemonConfig": {
    "ignore": ["*.json", "public/javascripts/*.js"]
  },


  "author": "@aqui",
  "license": "GPL-3.0"
}

The key must be nodemonConfig. Ignore rules can be specified as an array of globs or complete filenames

Or you can edit your package.json file to update the run scripts this way.

"scripts": {
    "dev": "nodemon server.js --ignore *.json"
  },
  • Related