Node.js Monorepos With pnpm Workspaces and Turborepo
When you have a frontend, an API, shared types, and a component library, keeping them in separate repositories creates version-syncing pain. A monorepo keeps them together with shared tooling.
Structure
apps/
web/ (Next.js)
api/ (Node.js API)
packages/
ui/ (shared React components)
types/ (shared TypeScript types)
config/ (eslint, tsconfig presets)
pnpm Workspaces
# pnpm-workspace.yaml
packages:
- "apps/*"
- "packages/*"
Reference internal packages:
{ "dependencies": { "@acme/types": "workspace:*" } }
pnpm is fast and disk-efficient, with strict dependency resolution that prevents accidental imports.
Turborepo
Turborepo runs tasks across packages with dependency awareness and caching:
{
"tasks": {
"build": { "dependsOn": ["^build"], "outputs": ["dist/**", ".next/**"] },
"test": { "dependsOn": ["^build"] },
"lint": {}
}
}
pnpm turbo run build --filter=web...
Unchanged packages are restored from cache — locally and with remote caching in CI.
Alternatives
Nx offers similar capabilities with more generators and plugins.
Tips
- Share TypeScript and ESLint configs as packages
- Use
--filterto build and test only affected packages in CI - Use changesets for versioning published packages
A monorepo isn't about one big repository. It's about changing shared code once and seeing the impact everywhere immediately.