2
  "scripts": {
    "start": "npm run prod",
    "build": "npm-run-all clean transpile",
    "server": "node ./dist/bin/www",
    "dev": "npm run lint && NODE_ENV=development nodemon --inspect=notifications:9236 --exec babel-node bin/www",
    "prod": "NODE_ENV=production npm-run-all build server",
    "transpile": "babel ./ --out-dir dist",
    "lint": "eslint '*.js' ",
    "lint:watch": "watch 'npm run lint' ",
    "precommit": "npm run lint",
    "prepush": "npm run lint",
    "clean": "rimraf dist",
    "test": "jest"
  }

I have multiple microservices on docker, each one contains similar scripts in their package.json. Whenever I make a change and save the file, nodemon does not detect the change & restart the server.

Nodemon does start when a microservice is booted up, outputting the following:

[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): **/* public/**/*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `babel-node --inspect=notifications:9236 bin/www`

I have to mention, this is a project built on Mac OS and I am currently running it on Windows, if it is any relevant.

Mad SQL
  • 47
  • 2
  • 8

4 Answers4

2

It's relevant on windows, because the file system difference in containers that run unix Duplicate question

if you setup nodemon.json to poll changes it should update, but it is very expensive memory wise

{
 "verbose": true,
 "watch": ["src/**/*.ts"],
 "exec": "ts-node ./src/index.ts",
 "pollingInterval": 100,
 "legacyWatch": true
}
M-Raw
  • 779
  • 4
  • 10
  • 1
    Adding legacyWatch did the trick. I've seen this before in other questions but what I didn't realize is that we use the config for nodemon in our package.json instead of a different json. The fact that you wrote out a more complete config helped me find it out in our project. Thanks. :) – Mad SQL Jan 21 '22 at 17:24
  • `"legacyWatch": true` fixed it for me on Windows 11 – btx Jun 22 '23 at 19:50
0

In whatever start script you are trying to run, you need to include nodemon

ex:

"start": "nodemon run prod"
roger
  • 192
  • 11
  • I have tweaked it to the following: "scripts": { "start": "nodemon run prod", "build": "npm-run-all clean transpile", etc... } Still does not work. – Mad SQL Jan 21 '22 at 15:38
  • but did you replace `npm` with `nodemon` for the `build`, as well as all the other ones? – roger Jan 21 '22 at 15:53
0

Maybe it’s already the case, but do you have your code folder as a volume ? Because if you don’t use a volume to share your local changes with the dockerized files, it won’t update because the files will stay the same

jeremynac
  • 1,204
  • 3
  • 11
0

I'm watching files via nodemon --watch '**/*' this will finds any changes in the nested files

jawn
  • 851
  • 7
  • 10