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 a named script
npm run <script>

# Run a package.json script.

Run a script quietly
npm run --silent <script>

# Reduce npm log noise when running scripts.

Pass args to a script
npm run build -- --watch

# Pass additional arguments after `--`.

Run test script
npm test

# Shortcut for `npm run test`.

Run start script
npm start

# Shortcut for `npm run start`.

Run stop script
npm stop

# Shortcut for `npm run stop`.

Rebuild native modules
npm rebuild

# Rebuild packages with install scripts or native addons.

## Workspace basics
Create a new workspace
npm init -w packages/app -y

# Create a workspace and update the root workspaces list.

Install all workspace dependencies
npm install --workspaces

# Run install across all configured workspaces.

Run script in all workspaces
npm run build --workspaces

# Run a script in all workspaces.

Run script in one workspace
npm run test --workspace=@acme/app

# Run a script for one specific workspace.

Include workspace root
npm run build --workspaces --include-workspace-root

# Run scripts in workspaces and the root package.

## Execution helpers
Run a binary from a package
npm exec eslint .

# Run a local binary inside the project context.

Run a package temporarily
npm exec --package cowsay -- cowsay hello

# Download a package temporarily and run its binary.

Run a create-* initializer
npm create vite@latest my-app

# Use create-* scaffolding through npm.

## Lifecycle patterns
Run scripts in foreground
npm install --foreground-scripts

# Surface script output directly in the terminal.

Run script only if it exists
npm run lint --if-present

# Avoid failing when a script is missing.

Disable lifecycle scripts
npm config set ignore-scripts true

# Turn off lifecycle scripts globally or locally.

Recommended next

No recommendations yet.