Manage related packages with npm workspaces
Quick answer
Workspaces let one npm project coordinate several local packages. npm links workspace packages into its install tree and can run commands in selected packages.
Tooling examples
Example 1. Context: projects/npm-lab. Run in a fresh prepared fixture copy; see its README. Local check available; consult validation evidence for what was asserted.
npm pkg get workspacesExpected observation: The list contains packages/units.
Example 2. Context: projects/npm-lab. Run in a fresh prepared fixture copy; see its README. Local check available; consult validation evidence for what was asserted.
npm run --silent --workspace=@lesson/units checkExpected observation: units ok
How the tooling works
The root declares packages/units in workspaces. That package has its own manifest, name and API. The root depends on @lesson/units using a matching version, which resolves to the local workspace in the lab. Use npm run --workspace with a package name for targeted commands. A monorepo is a repository organization choice; it does not remove the need for explicit dependency declarations or public interfaces. Test packages individually and at their boundaries.
Common mistakes
Do not assume every package can import every sibling without declaring its dependency. That may fail outside the monorepo.
Practice
Run the units script from the root, then inspect its own package name and exported function.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Manage related packages with npm workspaces — Knowledge Check
Assess tooling contracts, diagnostic reasoning and transfer to a project.
Which field identifies local workspace directories?
How can npm target a script to one workspace?
Why should workspace dependencies be declared explicitly?
In Manage related packages with npm workspaces, what is the expected observation for example 1 in its documented setup? npm pkg get workspaces
In Manage related packages with npm workspaces, what is the expected observation for example 2 in its documented setup? npm run --silent --workspace=@lesson/units check