Home > Software design >  watching folder using nodemon
watching folder using nodemon

Time:10-27

I'm trying to watch changes in my src folder where there would be serveral js files. How can I achieve this? When I run the dev script, I get the console.log from the index file but not from world and hello files. Can anyone explain how can I achieve to get all console.log appears?

directory:

folder
 ├── src
 |   ├── hello.js
 |   ├── index.js
 |   └── world.js
 | .gitignore
 | package.json
 | README.md

package.json:

{
  "name": "",
  "version": "1.0.0",
  "description": "",
  "main": "src",
  "scripts": {
    "dev": "nodemon --watch src"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "nodemon": "^2.0.14"
  }
}

files in src:

// index.js
console.log('index.js')
// world.js
console.log('world.js')
// hello.js
console.log('hello.js')

CodePudding user response:

Nodemon starts a single .js file as an entrypoint which would be your index.js. If your this file doesn't import the other files to execute the code inside them you will not see the other console.log.

You can take a look at this answer to see how to run nodemon on multiple files side by side.

  • Related