Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodemon not reloading. What's wrong with this nodemon.json file

This is my nodemon.json

{ 
    "watch": ["src/**/*.ts"],
    "exec": "node out/index.js" 
}

I run the nodemon by executing:

nodemon

In root nodejs directory

This is output:

 % nodemon                                                                                                     
[nodemon] 1.11.0                                                                                
[nodemon] to restart at any time, enter `rs`                                                                                                                       
[nodemon] watching: src/**/*.ts                                                                                                                       
[nodemon] starting node out/index.js
Yay! Started app!

But when I edit any ts file in src nodemon doesn't restart the app.

UPDATE

Running nodemon --watch src/index.ts --exec 'node out/index.js'

Works and reloads the app on modifying index.ts

However, running with wildcard

nodemon --watch 'src/**/*.ts' --exec 'node out/index.js'

or

nodemon --watch src --exec 'node out/index.js'

Doesn't reload the app.

like image 360
VsMaX Avatar asked May 05 '17 11:05

VsMaX


People also ask

How do I fix Nodemon is not working?

Use npx to solve the error "'nodemon' is not recognized as an internal or external command, operable program or batch file", e.g. npx nodemon server. js or install the package globally by running npm install -g nodemon and make sure your PATH environment variable is set up correctly.

Where can I find Nodemon json?

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. An alternative local configuration file can be specified with the --config option.

How do you refresh Nodemon?

When Nodemon restarts the ExpressJS server on changes, Livereload recreates the server and sends to the browser a refresh command when connected liveReloadServer. refresh("/"); . app.


1 Answers

Solved!

By running nodemon in verbose mode I have discovered that by default it watches only *.js files, regardless of what wildcard you are watching. Therefore adding -e ts to the command fixes the problem:

nodemon --watch src/ --exec 'node out/index.js' -e ts

If someone uses nodemon.json here is mine after fix:

{ 
    "watch": ["src"],
    "exec": "tsc && node out/index.js" ,
    "ext": "js, json, ts, proto"
}
like image 89
VsMaX Avatar answered Oct 21 '22 20:10

VsMaX