What is a monorepo, and what specific tooling (like npm workspaces or Turborepo) helps manage multiple related Node.js packages within a single repository?
Short answer
A monorepo houses multiple related, independently versionable packages (a shared library, a backend API, a frontend app) within a single Git repository, rather than splitting them across separate repositories -- npm workspaces (built into npm) let these packages reference each…
Advertisement
AModel answer
A monorepo houses multiple related, independently versionable packages (a shared library, a backend API, a frontend app) within a single Git repository, rather than splitting them across separate repositories -- npm workspaces (built into npm) let these packages reference each other locally without needing to be published to a registry first, while tools like Turborepo or Nx add build-caching and task-orchestration on top, only rebuilding and retesting packages actually affected by a given change.
// package.json at the repo root
{
"workspaces": ["packages/*"]
}
// packages/api/package.json can depend on a sibling package directly
"dependencies": { "@myorg/shared-utils": "workspace:*" }Real-world example
A company splits their shared validation logic, backend API, and admin dashboard into separate npm workspace packages within one monorepo, letting the API import the shared validation package directly during local development without needing to publish it to a private registry first.
Likely follow-ups
- What's the tradeoff between a monorepo and separate repositories for related but independently deployable services?
- How does a tool like Turborepo's build caching actually determine which packages need to be rebuilt after a given change?
Related topics