Development mode configures a microservice for rapid iteration rather than production performance and security. Live reload restarts the service after code changes, shortening the feedback loop. section 2.6.8 section 2.9
Set up development mode with a local project and an npm script:
- Install nodemon as a development dependency. section 2.6.8
- Add a start:dev script that runs nodemon against the service entry point. section 2.6.8
- Run npm run start:dev; reserve npm start for the production-mode command. section 2.6.8
Running a microservice during development
A package configuration can map start:dev to nodemon src/index.js. Running npm run start:dev then watches the service, restarts it after edits, and applies changes without manually stopping and starting the process. section 2.6.8 section 10.5.1
Listing 2.7 Adding a start script for development
{
"name": "example-3",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"start": "node src/index.js", #1
"start:dev": "nodemon src/index.js" #2
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^5.0.0-beta.1"
},
"devDependencies": { #3
"nodemon": "^2.0.18" #4
}
}
Use the package configuration listing to inspect the separate production and development scripts, including nodemon as a development dependency. section 2.6.8
