Node.js Monorepo example with npm Workspaces
Monorepo structure of TypeScript and NestJS project using Nx and npm Workspaces
- Not using NestJS monorepo mode.
- Use Nx on top of the npm workspace.
- Nx alone can handle releases (
versioning
→changelog
→publishing
), so it's more scalable than usingTurborepo
orLerna
alone.
npm ci
npm run lint
npm run test
npm run build
# The above command can also be used like this:
npx nx run-many -t=lint,test,build
# Run tasks affected
npx nx affected -t=build
# package manage to a specific workspace
npm i -w sample-nestjs-app install-package
npm un -w sample-nestjs-app uninstall-package
npm ci -w sample-nestjs-app
# launch the development process
npx nx run sample-nestjs-app:dev
# execute npm tasks
npx nx run workspace-name:any-task
npx nx exec ---projects workspace-name -- any-task
npm run any-task -w workspace-name
# https://docs.npmjs.com/cli/v9/commands/npm-ci#omit
npm ci -w sample-nestjs-app --omit=dev
- See https://docs.npmjs.com/cli/v9/commands/npm-init#workspaces-support
- Modify workspace by refer to the sample code. or edit after copy-paste
npm init -w apps/app-name
npm init -w packages/package-name
- Modify the pah mapping in tsconfig.json.
+-- apps
| +-- sample-app // TypeScript simple sample-app
| +-- sample-nestjs-app // NestJS server sample-app
+-- packages
| +-- sample-lib // TypeScript simple sample-package
| +-- sample-nestjs-lib // NestJS module sample-package
+-- eslint.config.mjs // ESLint common configuration
+-- vitest.config.ts // Vitest common configuration
+-- nx.json // Nx task pipeline configuration