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
| Flag | Meaning |
|---|---|
| -- | everything after it goes to the script, not to npm |
| --if-present | exit quietly when the script is missing |
| -w <workspace> | run it in one workspace |
| --workspaces | run it in every workspace |
| -s | hide npm own output |
Examples
npm run buildruns the build script from package.json
npm run test -- --watchpasses --watch to the test runner, not to npm
npm runwith 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