Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodemon watch directory for changes

I know how to do nodemon server.js but what if I want to do nodemon ./src

I want restart node on any changes in the directory of src.

When I do above and it say cannot find module babelprac\src

I am also doing in another command window : npm run scripts:watch

The script is

"scripts" : {   "scripts" : "babel src --source-maps-inline --out-dir dist",   "scripts:watch" : "babel src --watch --source-map-inline --out-dir dist" }, 

That runs the watch but I want to run the script in src or dist to see the console.logs

I aslo tried nodemon --watch ./src. It says it can't find index.js.

I am on windows 7

My working directory is babelprac

like image 420
jack blank Avatar asked Jan 18 '17 21:01

jack blank


People also ask

What does Nodemon watch do?

nodemon will watch the files in the directory that nodemon was started, and if they change, it will automatically restart your node application. nodemon does not require any changes to your code or method of development. nodemon simply wraps your node application and keeps an eye on any files that have changed.

Does Nodemon ignore Node_modules?

Note that by default, nodemon will ignore the . git and node_modules/**/node_modules directories.

Where is Nodemon json file?

From the official documentation and github page: nodemon supports local and global configuration files. These are usually named nodemon. json and can be located in the current working directory or in your home directory.


2 Answers

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

like image 172
Kody Avatar answered Sep 18 '22 10:09

Kody


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

like image 20
Hank Chan Avatar answered Sep 19 '22 10:09

Hank Chan