Node.js theorytheory 0/50 · 0%
Tooling · hard

48. Monorepos and workspaces

Managing multiple related packages together.

A monorepo holds several related packages (a shared library, an API, a CLI) in one repository. npm/pnpm/yarn "workspaces" let those packages depend on each other locally (symlinked in `node_modules`) without publishing to a registry first, and installs dependencies for all packages in one pass.

json
{
  "name": "my-web3-monorepo",
  "private": true,
  "workspaces": ["packages/*"]
}
packages/
  shared-types/   (name: "@app/shared-types")
  api/            (depends on "@app/shared-types": "workspace:*")
  indexer/

Workspaces make it practical to share types and utility code (e.g. chain configs, ABI definitions) between an API service and an indexer without copy-pasting or publishing an internal npm package for every small change.

Check your understanding

  1. 1. What problem do workspaces solve?

  2. 2. What kind of code is a good candidate to extract into a shared workspace package?

  3. 3. How does a package.json enable npm workspaces?