run
npm run
Executes a script from the `scripts` block of package.json in a shell where node_modules/.bin is on PATH. Alias: `run-script`; running `npm run` with no arg lists every available script.
npm run <script> [-- <args>] Common flags
| Flag | Purpose |
|---|---|
| -- | Separator; everything after it is forwarded verbatim to the underlying script |
| --if-present | Silently succeed when the script is not defined |
| --workspace <name> (-w) | Run inside a specific workspace |
| --workspaces (-ws) | Run the script in every workspace that defines it |
| --silent (-s) | Suppress npm's own log framing around the script |
Examples
npm run build Run the "build" script from package.json
npm run test -- --watch Forward --watch to the underlying test runner
npm run lint -ws --if-present Run lint in every workspace that has it
Gotcha
Arguments before `--` are consumed by npm itself; put runner flags after `--` or they will be silently dropped. Only `start`, `stop`, `test`, and `restart` have shortcut verbs — every other script requires `run`.
Related commands
npm start
Shortcut for `npm run start` — runs the `start` script from package.json. If no `start` script is defined, npm falls back to `node server.js`.
npm test
Shortcut for `npm run test` — runs the `test` script from package.json. Aliases: `npm t`, `npm tst`.
npm exec (npx)
Runs a package's binary from a local install, the cache, or on-the-fly from the registry without a global install. `npx` is the shell-friendly shim; both are equivalent in npm 10+.