Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodemon ignore directory

In a Universal Javascript app, I would like nodemon to ignore client directory changes.

I have tried the following:

"devStart": "nodemon server/server.js --ignore 'client/*' --exec babel-node",
"devStart": "nodemon server/server.js --ignore 'client/' --exec babel-node",
"devStart": "nodemon server/server.js --ignore client/ --exec babel-node",
"devStart": "nodemon --ignore 'client/*' server/server.js --exec babel-node",
"devStart": "nodemon --ignore 'client/' server/server.js --exec babel-node",
"devStart": "nodemon --ignore client/ server/server.js --exec babel-node",

None of these work.

File structure:

+-server
+-client
+-package.json <------- where nodemon script is

However this is not working. Pretty sure it is a pattern issue.

Any ideas?

like image 689
softcode Avatar asked Jan 28 '17 18:01

softcode


People also ask

How do I ignore Nodemon files?

You can use ls 'your exlusions' && nodemon app. js (not cross platform). If you are willing to write code for it, you can listen to nodemon 'start' or 'restart' event and print excluded files by reading nodemon config and expanding glob patterns in "ignore" array.

Does Nodemon ignore Node_modules?

Note that by default, nodemon will ignore the . git and node_modules/**/node_modules directories.

What is Nodemon JSON?

Nodemon is a utility depended on about 3 million projects, that will monitor for any changes in your source and automatically restart your server. Perfect for development. Swap nodemon instead of node to run your code, and now your process will automatically restart when your code changes.

How do you stop a Nodemon server?

Press Ctrl + C to exit from Nodemon on windows.


2 Answers

You need to replace .. with ., or just reference client/ directly, also you will need to remove the asterisk:

"devStart": "nodemon --ignore ./client/ --exec babel-node src/server.js"

Or

"devStart": "nodemon --ignore client/ --exec babel-node src/server.js"

According to nodemon docs this is how to ignore a directory via command line:

nodemon --ignore lib/ --ignore tests/

Also note that nodemon will only restart the node process, if you change the npm script you will need to kill the process and re-run npm run devStart

like image 161
hackerrdave Avatar answered Oct 22 '22 21:10

hackerrdave


In the very likely circumstance that you're using nodemon in a configuration file, you can create a separate configuration entry for those files to be ignored. Bonus, a cleaner looking nodemon call, especially if files to ignore grows large.

For example, this package.json instructs nodemon to ignore directory test:

{
  "scripts": {
    "test": "jest",
    "start": "nodemon server.js"
  },
  "nodemonConfig": {
      "ignore": ["test/*"]
  }
}

Find the complete instructions for nodemon configuration file settings here.

As in the other answer, be sure to restart nodemon for the configuration changes to take effect.

like image 53
Andrew Philips Avatar answered Oct 22 '22 22:10

Andrew Philips