admin管理员组

文章数量:1279120

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?

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?

Share Improve this question edited Apr 9, 2016 at 9:26 BAR asked Apr 9, 2016 at 9:10 BARBAR 17.1k27 gold badges106 silver badges204 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 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.

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 remended to add the nodemon as development dependency rather than a main/ build one as follows:

"devDependencies": {
  "nodemon": "^2.0.12"
},
"dependencies": {
}

本文标签: javascriptNodemon watch all project directoriesStack Overflow