Lesson 9 / 30
npm Scripts
Wrap common commands in npm scripts such as start, test and dev, and run them with npm run.
By Rahul Agarwal · 15 years in web development · Updated 1 Oct 2026
The scripts field
Define named commands in package.json, then run them with npm run.
{
"scripts": {
"start": "node index.js",
"dev": "node --watch index.js",
"test": "node --test"
}
}Running scripts
start and test are special — run them without run.
npm start # runs "node index.js"
npm test # runs "node --test"
npm run dev # custom scripts need "run"Quick check: Which two script names can you run without typing `run`?
- dev and build
- start and test
- install and stop
- lint and format
Answer
start and test — `npm start` and `npm test` are shortcuts baked into npm; every other script name needs `npm run <name>`.