www.LinuxHowtos.org
NP-RUN
Section: (1)Updated: October 2025
Index Return to Main Contents
NAME
np-run- Run arbitrary package scriptsSynopsis
-
npm run <command> [lB- <args>[rB] aliases: ru-script, rum, urn
Description
This runs an arbitrary command from a package's "scripts" object. If no "command" is provided, it will list the available scripts. run[lB-script[rB] is used by the test, start, restart, and stop commands, but can be called directly, as well. When the scripts in the package are printed out, they're separated into lifecycle (test, start, restart) and directl-run scripts. Any positional arguments are passed to the specified script. Use - to pass --prefixed flags and options which would otherwise be parsed by npm. For example:-
npm run test--grep="pattern"
-
"scripts": {"test": "tap test/*.js"}
-
"scripts": {"test": "node_modules/.bin/tap test/*.js"}
Workspaces support
You may use the [rs]fBworkspace[rs]fR la/usin-npm/config#workspacera or [rs]fBworkspaces[rs]fR la/usin-npm/config#workspacesra configs in order to run an arbitrary command from a package's "scripts" object in the context of the specified workspaces. If no "command" is provided, it will list the available scripts for each of these configured workspaces. Given a project with configured workspaces, e.g:-
- package.json - packages - a | - package.json - b | - package.json - c - package.json
-
{ "workspaces": [lB] "./packages/*" [rB] }
-
npm test-workspaces
Filtering workspaces
It's also possible to run a script in a single workspace using the workspace config along with a name or directory path:-
npm test-workspace=a
-
npm test-w a-w b
Configuration
workspace
-
- *
- Default:
- *
- Type: String (can be set multiple times)
Enable running a command in the context of the configured workspaces of the current project while filtering by running only the workspaces defined by this configuration option. Valid values for the workspace config are either:
-
- *
- Workspace names
- *
- Path to a workspace directory
- *
- Path to a parent workspace directory (will result in selecting all workspaces within that folder)
When set for the npm init command, this may be set to the folder of a workspace which does not yet exist, to create the folder and set it up as a brand new workspace within the project. This value is not exported to the environment for child processes.
workspaces
-
- *
- Default: null
- *
- Type: null or Boolean
Set to true to run the command in the context of all configured workspaces. Explicitly setting this to false will cause commands like install to ignore workspaces altogether. When not set explicitly:
-
- *
- Commands that operate on the node_modules tree (install, update, etc.) will link workspaces into the node_modules folder.- Commands that do other things (test, exec, publish, etc.) will operate on the root project, unless one or more workspaces are specified in the workspace config.
This value is not exported to the environment for child processes.
includ-workspac-root
-
- *
- Default: false
- *
- Type: Boolean
Include the workspace root when workspaces are enabled for a command. When false, specifying individual workspaces via the workspace config, or all workspaces via the workspaces flag, will cause npm to operate only on the specified workspaces, and not on the root project. This value is not exported to the environment for child processes.
i-present
-
- *
- Default: false
- *
- Type: Boolean
If true, npm will not exit with an error code when run is invoked for a script that isn't defined in the scripts section of package.json. This option can be used when it's desirable to optionally run a script when it's present and fail if the script fails. This is useful, for example, when running scripts that may only apply for some builds in an otherwise generic CI setup. This value is not exported to the environment for child processes.
ignor-scripts
-
- *
- Default: false
- *
- Type: Boolean
If true, npm does not run scripts specified in package.json files. Note that commands explicitly intended to run a particular script, such as npm start, npm stop, npm restart, npm test, and npm run will still run their intended script if ignor-scripts is set, but they will not run any pr- or pos-scripts.
foregroun-scripts
-
- *
- Default: false unless when using npm pack or npm publish where it defaults to true
- *
- Type: Boolean
Run all build scripts (ie, preinstall, install, and postinstall) scripts for installed packages in the foreground process, sharing standard input, output, and error with the main npm process. Note that this will generally make installs run slower, and be much noisier, but can be useful for debugging.
scrip-shell
-
- *
- Default: '/bin/sh' on POSIX systems, 'cmd.exe' on Windows
- *
- Type: null or String
The shell to use for scripts run with the npm exec, npm run and npm init <packag-spec> commands.
See Also
-
- *
- npm help scripts
- *
- npm help test
- *
- npm help start
- *
- npm help restart
- *
- npm help stop
- *
- npm help config
- *
- npm help workspaces