An npm script gives a project a memorable command for starting an application, running tests, or using a development tool. Define the command under `scripts` in `package.json`. Callers can then use the project’s command without knowing its entry-point filename or tool-specific arguments. section 2.6.7 section 9.5.8
Start a microservice
Set `"start": "node src/index.js"` in `package.json`, install dependencies with `npm install`, then run `npm start`. For a production-only dependency installation, use `npm install --omit=dev` instead. section 2.6.7
Use `npm run` for a custom script name. For example, `"start:dev": "nodemon src/index.js"` supports live reloading when nodemon is installed as a development dependency; invoke it with `npm run start:dev`. Unlike `start`, `start:dev` is a project convention, not a special npm command. section 2.6.8
Testing follows the same pattern: map `test` to Jest and run `npm test`. A separate `test:watch` script can run `jest --watchAll` through `npm run test:watch`. Another project can map `test` to Playwright instead, preserving `npm test` while changing the underlying tool. The Playwright setup shown does not provide a watch-mode script. section 9.5.8 section 9.8.6
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
}
}
A complete `package.json` example places the standard start command and a nodemon-based development command alongside their respective dependencies. section 2.6.8



