Nodemon watch all project directories
Asked Answered
P

2

6

I believe nodemon is supposed to watch all directories for changes by default (expect for node_module, etc).

nodemon /bin/www 3000

But it's only monitoring changes to files in the root folder.

nodemon /bin/www 3000 
[nodemon] 1.9.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node ./bin/www /bin/www 3000`

How can I specify that it watch all folders in the project?

Procedure answered 9/4, 2016 at 9:10 Comment(0)
M
7

By default nodemon monitors the current working directory. If you want to take control of that option, use the --watch option to add specific paths:

nodemon --watch app --watch libs /bin/www 3000

Check official documentation: here.

Mellifluent answered 9/4, 2016 at 10:52 Comment(0)
P
3

Nodemon by default watches all directories in the project, but detects only changes in javascript files. You can add the following watch script to package.json file and it will automatically restart the script on any file change:

"scripts": {
  "start": "node ./bin/www",
  "watch": "nodemon ./bin/www --watch ./ --ext '*' localhost 3000"
}

the first argument here is the express server path that nodemon is supposed to restart/ run on any file change, the second is the file extensions which nodemon is supposed to watch changes on it, and the last two are the host and port on which your server is running.

Now, you can run:

$ npm run watch

and it should be working.

It is recommended to add the nodemon as development dependency rather than a main/ build one as follows:

"devDependencies": {
  "nodemon": "^2.0.12"
},
"dependencies": {
}
Pelecypod answered 1/10, 2021 at 16:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.