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