This is the portion from package.json
:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js",
"dev": "nodemon --watch app index.js"
},
All my code except the index.js
, package.json
and node_modules
resides in a sub folder called app
.
When I run using npm run dev
, nodemon watches the changes in app
folder and restarts if there's any changes. But won't restart if I make any changes in index.js
(entry point)
My folder structure:
|-- app/
|-- node_modules/
|index.js <--- nodemon not watching this file
|package.json
|package-lock.json
Why is it so?
EDIT:
Here's the solution (from @Pedro Filipe):
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js",
"dev": "nodemon index.js"
},
Nodemon watches the entry-point
to your project.
Which, In almost all the cases of node project is a single file which eventually imports other files and so on and so forth.
(Assuming that your entry-point
is index.js
i.e. you're importing your other files in there.) You can simply use the nodemon index.js
as the script for your dev
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js",
"dev": "nodemon index.js"
},