nodemon watch directory for changes

Nodemon expects it just as:

nodemon --watch src server.js

https://github.com/remy/nodemon#monitoring-multiple-directories

nodemon --watch app --watch libs app/server.js


I use this for hot replacement, nodemon --watch src and run tsc complier.

you can also check this article: https://medium.com/netscape/start-building-web-apps-with-koajs-and-typescript-366264dec608

"scripts": {
  "watch-server": "nodemon --watch 'src/**/*' -e ts,tsx --exec 'ts-node' ./src/server.ts"
}

Nodemon also has a more fine-grained approach for watching folders and files. Use nodemon.json to specify what files and the types of files to watch, as below in your case:

{
  "watch": ["server.js", "src/"],
  "ext": "js, css"
}

Having a nodemon.json is particularly useful when the number and types of watched files start to bloat, and also when you want to run a script upon each server restart. For nodemon to read in the configuration, nodemon.json should be placed at the root directory of your project, along with every other hidden and not hidden json files.

Below is a good place to start your nodemon.json.

https://github.com/remy/nodemon/blob/master/doc/sample-nodemon.md