Skip to content

CatsMiaow/node-monorepo-workspaces

Repository files navigation

node-monorepo-workspaces

Node.js Monorepo example with npm Workspaces

Introduction

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 (versioningchangelogpublishing), so it's more scalable than using Turborepo or Lerna alone.

Continuous Integration

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

Development

# 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

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
+-- eslint.config.mjs // ESLint common configuration
+-- vitest.config.ts // Vitest common configuration
+-- nx.json // Nx task pipeline configuration

Links

About

Node.js Monorepo example with npm Workspaces

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published