22

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.

VsMaX
  • 1,685
  • 2
  • 16
  • 28
  • You will need a `ts-node` package. Refer: https://stackoverflow.com/questions/37979489/how-to-watch-and-reload-ts-node-when-typescript-file-changes/37979548 – Suhail Gupta May 05 '17 at 11:38
  • I have started with the link you provided, but it doesn't work for me, therefore I started simplifiying the script and eventually ended up with that one. But it also doesn't work – VsMaX May 05 '17 at 11:43

3 Answers3

68

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"
}
Judah Gabriel Himango
  • 58,906
  • 38
  • 158
  • 212
VsMaX
  • 1,685
  • 2
  • 16
  • 28
  • 1
    Watching for js files in the `out` directory would make more sense if you're executing `node out/index.js` – sparebytes Mar 22 '19 at 18:29
  • nodemon.json ```{ "watch": ["src/*", "package.json"], "ext": "ts js json" } ``` in package.json { "scripts": { "start": "nodemon -r source-map-support/register ." }, } when run with `yarn start` you will get ```$ nodemon -r source-map-support/register . [nodemon] 2.0.7 [nodemon] to restart at any time, enter rs [nodemon] watching path(s): src/**/* lb3app/server/**/* package.json [nodemon] watching extensions: ts,js,json [nodemon] starting node -r source-map-support/register . Server is running at http://127.0.0.1::3000``` – chendu May 10 '21 at 07:49
0

I didn't have any luck with src/ watching either. I'm watching files via nodemon --watch '**/*' this will finds any changes in the nested files

jawn
  • 851
  • 7
  • 10
-1

Use single quotation for multi-value args like `--exec' in the package.json script.

e.g. I changed "nodemon --exec npm run build-langs" to "nodemon --exec 'npm run build-langs'" and worked.

Masih Jahangiri
  • 9,489
  • 3
  • 45
  • 51