NPM Workspaces in NPM

From the NPM Package Manager cheat sheet ยท Workspaces & Advanced ยท verified Jul 2026

NPM Workspaces

Manage multiple packages in monorepo

bash
// Root package.json
{
  "name": "my-monorepo",
  "workspaces": [
    "packages/*",
    "apps/*"
  ]
}

# Install in workspace
npm install express -w packages/api
npm install -D jest --workspaces

# Run scripts in workspace
npm run build -w packages/core
npm run test --workspaces

# Execute in all workspaces
npm run build --workspaces --if-present

# Create new workspace
npm init -w packages/new-package
๐Ÿ”ด Advanced - Great for monorepos
๐Ÿ’ก Workspaces share dependencies (hoisting)
๐Ÿ“Œ Reference internal deps by name + semver (npm has no workspace: protocol)
โšก Reduces duplication and install time
๐Ÿ”— Related: lerna, nx for advanced monorepos
workspacesmonorepo

More NPM tasks

Back to the full NPM Package Manager cheat sheet