npm Scripts & Workspaces

Scripts, lifecycle hooks, npm exec, and workspace workflows.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Scripts and lifecycle

Run custom package scripts and understand lifecycle behavior.

Run a named script

Run a package.json script.

bashANYnpmrunscripts
bash
npm run <script>

Run a package.json script.

Run a script quietly

Reduce npm log noise when running scripts.

bashANYnpmrunscripts
bash
npm run --silent <script>

Reduce npm log noise when running scripts.

Pass args to a script

Pass additional arguments after `--`.

bashANYnpmrunscripts
bash
npm run build -- --watch

Pass additional arguments after `--`.

Run test script

Shortcut for `npm run test`.

bashANYnpmtestscripts
bash
npm test

Shortcut for `npm run test`.

Run start script

Shortcut for `npm run start`.

bashANYnpmstartscripts
bash
npm start

Shortcut for `npm run start`.

Run stop script

Shortcut for `npm run stop`.

bashANYnpmstopscripts
bash
npm stop

Shortcut for `npm run stop`.

Rebuild native modules

Rebuild packages with install scripts or native addons.

bashANYnpmrebuild
bash
npm rebuild

Rebuild packages with install scripts or native addons.

Workspace basics

Initialize and inspect npm workspaces.

Create a new workspace

Create a workspace and update the root workspaces list.

bashANYnpmworkspaceinit
bash
npm init -w packages/app -y

Create a workspace and update the root workspaces list.

Install all workspace dependencies

Run install across all configured workspaces.

bashANYnpmworkspacesinstall
bash
npm install --workspaces

Run install across all configured workspaces.

Run script in all workspaces

Run a script in all workspaces.

bashANYnpmworkspacesscripts
bash
npm run build --workspaces

Run a script in all workspaces.

Run script in one workspace

Run a script for one specific workspace.

bashANYnpmworkspacescripts
bash
npm run test --workspace=@acme/app

Run a script for one specific workspace.

Include workspace root

Run scripts in workspaces and the root package.

bashANYnpmworkspaceroot
bash
npm run build --workspaces --include-workspace-root

Run scripts in workspaces and the root package.

Execution helpers

Use npm exec and package binaries in mono-repos.

Run a binary from a package

Run a local binary inside the project context.

bashANYnpmexecbin
bash
npm exec eslint .

Run a local binary inside the project context.

Run a package temporarily

Download a package temporarily and run its binary.

bashANYnpmexectemporary
bash
npm exec --package cowsay -- cowsay hello

Download a package temporarily and run its binary.

Run a create-* initializer

Use create-* scaffolding through npm.

bashANYnpmcreatescaffold
bash
npm create vite@latest my-app

Use create-* scaffolding through npm.

Lifecycle patterns

Commands related to lifecycle hooks and script troubleshooting.

Run scripts in foreground

Surface script output directly in the terminal.

bashANYnpmscriptsdebug
bash
npm install --foreground-scripts

Surface script output directly in the terminal.

Run script only if it exists

Avoid failing when a script is missing.

bashANYnpmscripts
bash
npm run lint --if-present

Avoid failing when a script is missing.

Disable lifecycle scripts

Turn off lifecycle scripts globally or locally.

bashANYnpmconfigscripts
bash
npm config set ignore-scripts true

Turn off lifecycle scripts globally or locally.

Recommended next

No recommendations yet.