What does npm run do?
npm run runs a script described in the "scripts" section of package.json. It is a convenient way to run commands through npm without typing them directly into the terminal every time.
Example in package.json
json
{
"scripts": {
"start": "node index.js",
"build": "webpack",
"dev": "vite"
}
}How to run them
bash
npm run start
npm run build
npm run devWhat happens
- npm looks up the command in
"scripts" - runs the given line in the command shell
- adds local binaries from
node_modules/.binto PATH (for example,webpack,vite,eslint, etc.)
A shortcut
For a script named start, it's enough to just run:
bash
npm startThis works the same as npm run start.
Summary
npm run executes the commands defined in package.json and lets you run project tools (webpack, vite, nodemon, tests, linters, and so on) in a uniform way.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.