Home·Terminal commands

npm run

Packages and runtimes

Usage

npm run <script> [-- <args>]

Runs a command from the scripts section of package.json; arguments meant for the script need a bare -- first, and only start and test can be called without run.

Common flags

FlagMeaning
--everything after it goes to the script, not to npm
--if-presentexit quietly when the script is missing
-w <workspace>run it in one workspace
--workspacesrun it in every workspace
-shide npm own output

Examples

npm run build

runs the build script from package.json

npm run test -- --watch

passes --watch to the test runner, not to npm

npm run

with no name, lists the scripts that exist

The question is always what goes where: inside this project, or on the whole machine.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does npm run do?

Runs a command from the scripts section of package.json; arguments meant for the script need a bare -- first, and only start and test can be called without run.

Q. How do I type it?

npm run <script> [-- <args>] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

5 are listed here; the full set is in man npm. This command sits under Packages and runtimes.

Related commands

man page: man npm-run