Home

Awesome

node-monorepo-workspaces

Node.js Monorepo example with npm Workspaces

Introduction

Monorepo structure of TypeScript and NestJS project using Lerna and npm Workspaces

Continuous Integration

npm ci
npm run lint
npm run test
npm run build
# The above command can also be used like this:
npx lerna run lint,test,build
#= npx nx run-many --target=build

# Run tasks affected
npx lerna run build --since=main
#= npx nx affected --target=build

Development

# package manage to a specific workspace
npm i -w sample-nestjs-app install-package
npm uninstall -w sample-nestjs-app uninstall-package
npm ci -w sample-nestjs-app

# launch the development process
npx lerna run dev --scope=sample-nestjs-app
#= npx nx run sample-nestjs-app:dev

# execute npm tasks
npx lerna run any-task --scope=workspace-name
npx lerna exec npm run any-task --scope=workspace-name
#= npx nx run workspace-name:any-task
npm run any-task -w workspace-name

Production

# https://docs.npmjs.com/cli/v9/commands/npm-ci#omit
npm ci -w sample-nestjs-app --omit=dev

Create a new workspace (apps or packages)

Apps

Packages

Folders

+-- 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
+-- .eslintrc // ESLint common configuration
+-- jest.config.ts // Jest common configuration
+-- lerna.json // Lerna configuration
+-- nx.json // Nx task pipeline configuration

Links