- Node.js (v20 or higher)
- pnpm installed globally (
npm install -g pnpm)
npx create-nx-workspace@latest nestjs-migrate-nx --preset=ts --packageManager=pnpm
cd nestjs-migrate-nxpnpm install -D @nx/nest @nx/node @nx/eslint @nx/jest @nx/webpack# Framework library (infrastructure)
nx g @nx/nest:lib --name=framework --directory=libs/framework --buildable
# Core domain library (core logic)
nx g @nx/nest:lib --name=core --directory=libs/core --buildable
# Plugins library (extensibility)
nx g @nx/nest:lib --name=plugins --directory=libs/plugins --buildable
# Shared library (utilities)
nx g @nx/nest:lib --name=shared --directory=libs/shared --buildable# Admin application
nx g @nx/nest:app --name=admin --directory=apps/admin
# API backend application
nx g @nx/nest:app --name=api --directory=apps/api
# Workers application (background jobs)
nx g @nx/nest:app --name=workers --directory=apps/workersnx run-many --target=build --all# Serve individual applications
nx serve api # http://localhost:3001
nx serve admin # http://localhost:3000
nx serve workers # Background process
# Or serve all applications in development mode
nx run-many --target=serve --all# Serve with watch mode
nx serve api --watch
# Serve with different port
nx serve api --port=4000
# Serve with production configuration
nx serve api --configuration=production# Test specific project
nx test api
nx test core
# Test all projects
nx run-many --target=test --all
# Test with watch mode
nx test api --watch# Lint specific project
nx lint api
# Lint all projects
nx run-many --target=lint --all
# Fix lint issues automatically
nx lint api --fix# Build specific project
nx build api
nx build core
# Build for production
nx build api --configuration=production
# Build all projects
nx run-many --target=build --all# Show project graph
nx graph
# Show project information
nx show project api
# List all projects
nx show projects# Add production dependency to specific project
nx g @nx/node:setup-build --project=api
pnpm add class-validator
# Add dev dependency to workspace
pnpm add -D @types/node
# Add dependency to specific library
pnpm add lodash --filter @nestjs-migrate-nx/coreSet up dependencies in project.json files:
{
"dependencies": {
"@nestjs-migrate-nx/shared": "*",
"@nestjs-migrate-nx/core": "*"
}
}export const environment = {
production: false,
databaseUrl: 'postgresql://localhost:5432/dev_db',
port: 3000,
};export const environment = {
production: true,
databaseUrl: process.env.DATABASE_URL,
port: process.env.PORT || 3000,
};# Kill process on port 3000
npx kill-port 3000
# Or use different port
nx serve api --port=3001# Clear Nx cache
nx reset
# Delete node_modules and reinstall
rm -rf node_modules
pnpm install# Check dependency graph
nx graph
# Verify imports use correct paths
# Use: @nestjs-migrate-nx/core instead of relative pathspnpm add @nestjs/typeorm typeorm pg
pnpm add @nestjs/passport @nestjs/jwt passport-jwt
pnpm add @nestjs/swagger swagger-ui-express
pnpm add nest-winston winston
pnpm add @nestjs/config{
"scripts": {
"dev:api": "nx serve api",
"dev:admin": "nx serve admin",
"dev:all": "nx run-many --target=serve --all",
"build:all": "nx run-many --target=build --all",
"test:all": "nx run-many --target=test --all",
"lint:all": "nx run-many --target=lint --all",
"graph": "nx graph"
}
}- API Application: http://localhost:3001
- Admin Application: http://localhost:3000
- Project Graph: Run nx graph and open browser
- Nx Console: Available as VSCode extension
- Nx Documentation: https://nx.dev/
- NestJS Documentation: https://docs.nestjs.com/
- GitHub Repository: Your workspace Git repo
This setup creates a scalable enterprise-grade NestJS monorepo with proper separation of concerns and buildable libraries.