nodemon - ignore the file and path

8.4k views Asked by At

I am using node js and the nodemon module.

Problem: If I change file in front-end the server will be automatically restarted.

Expected: If I change the few js or few files inside the path it should not restart the server.

I tried the following code:

nodemon --ignore 'public/javascripts/template_files/*.js'

But the above code not working. If I change any js files inside the template_files folders means the server restarting again and again.

1

There are 1 answers

0
Gabriel L. On BEST ANSWER

Based on the comments I now have enough information to explain what's going on.

In your package.json, your start script needs to look like this:

"scripts" : {
    "start" : "nodemon ./bin/www --ignore 'public/javascripts/template_files/*.js'"
},

That means, when you run npm start, the command nodemon should be run (monitoring all file changes), executing the ./bin/www file, but not monitoring those specific JS files. If a file (other than the ignored files) changes, re-execute the ./bin/www file.

What you were doing before was trying to execute nodemon --ignore 'public/javascripts/template_files/*.js' from the command line, which won't execute any particular file (IIRC), and also leaving the start script as nodemon ./bin/www, which will not ignore the files you want ignored.

Make the change to your package.json and only use npm start. Do not type nodemon directly into the command line, there is no need.