Code reloading shortens the time between saving a change and seeing its result. During development, a watcher detects source changes and restarts the affected microservice automatically. This is a development and testing workflow, not a reason to run a watcher in production. section 2.6.8
For a Node.js microservice, start with a runnable application:
- Install nodemon as a development dependency: `npm install --save-dev nodemon`. It need not be installed in production. section 2.6.8
- Keep `npm start` for the ordinary `node src/index.js` command. Add a `start:dev` npm script that runs `nodemon src/index.js`, then use `npm run start:dev` while editing. section 2.6.8
- If file changes are not detected under WSL2 or a virtual machine, use `nodemon --legacy-watch ./src/index.js`. This polls for changes instead of relying on filesystem watching; omit it elsewhere for slightly better performance. section 5.5.2
Listing 5.2 Setting up package.json for live reload with nodemon
{ "name": "history", "version": "1.0.0", "description": "", "main": "./src/index.js", "scripts": { "start": "node ./src/index.js", "start:dev": "nodemon --legacy-watch ./src/index.js" #1 }, --snip-- "dependencies": { "express": "^5.0.0-beta.1" }, "devDependencies": { "nodemon": "^2.0.21" } } #1 Uses nodemon to enable live reload for this microservice. When the code changes, nodemon automatically restarts the microservice.
The package configuration keeps the ordinary start command separate from the nodemon-based development command. section 5.5.2
Containers add a second requirement: the changed code must reach the running container. Code baked into a Docker image cannot be updated by editing the host copy. In development, Docker volumes share code between the computer and containers; nodemon can then restart the relevant microservice without rebuilding and restarting the entire application. Apply the same setup to each microservice managed by Docker Compose. Immutable images remain useful for production deployment and software-supply-chain verification. section 5.5 section 5.11
Check the feedback loop
Start the application with `docker compose up --build`. Change the history microservice’s startup message from “Hello world!” to “Hello computer!” and save. Its new message should appear in the Compose output; the unchanged video-streaming microservice should not restart. Try introducing an error, inspect the output, then fix and save the file to trigger another restart. section 5.5.5
The same feedback-loop idea applies to tests. `npx jest --watchAll` reruns all tests when code changes. With Git, `npx jest --watch` uses changed-file information for better performance. A project may expose test watching through a `test:watch` npm script. section 9.5.6 section 10.6.1



