Skip to content

Command Reference

Quick reference for common Nx commands used in the Petfolio monorepo.

Development Commands

Serve Applications

# Start main app
npx nx serve petfolio-business

# Start Storybook
npx nx storybook ui-component-library

# Start documentation
npx nx serve petfolio-docs

Build Commands

# Build specific project
npx nx build petfolio-business

# Build all projects
npx nx run-many --target=build --all

# Build with production configuration
npx nx build petfolio-business --configuration=production

# Build documentation
npx nx build petfolio-docs

Testing Commands

Unit Tests

# Run all tests
npx nx run-many --target=test --all

# Test specific project
npx nx test ui-component-library

# Watch mode
npx nx test ui-component-library --watch

# Coverage report
npx nx test ui-component-library --coverage

# Update snapshots
npx nx test ui-component-library --updateSnapshot

E2E Tests

# Run all e2e tests
npx nx e2e petfolio-ui-tests

# Run specific test file
npx nx e2e petfolio-ui-tests --spec=login.spec.ts

# Run in UI mode
npx nx e2e petfolio-ui-tests --ui

# Debug mode
npx nx e2e petfolio-ui-tests --debug

# Run headed (see browser)
npx nx e2e petfolio-ui-tests --headed

Linting Commands

# Lint all projects
npx nx run-many --target=lint --all

# Lint specific project
npx nx lint petfolio-business

# Auto-fix issues
npx nx lint petfolio-business --fix

# Lint only affected
npx nx affected:lint

Affected Commands

Only run tasks for projects affected by changes:

# Test affected projects
npx nx affected:test

# Lint affected projects
npx nx affected:lint

# Build affected projects
npx nx affected:build

# See affected projects
npx nx affected:graph

# Run any target on affected
npx nx affected --target=<target>

Dependency Graph

# Open interactive dependency graph
npx nx graph

# Focus on specific project
npx nx graph --focus=petfolio-business

# Exclude specific projects
npx nx graph --exclude=petfolio-docs

# Generate static HTML
npx nx graph --file=dep-graph.html

Run Many

Run a target across multiple projects:

# Run on all projects
npx nx run-many --target=test --all

# Run on specific projects
npx nx run-many --target=build --projects=petfolio-business,ui-component-library

# Run in parallel
npx nx run-many --target=lint --all --parallel=3

# With configuration
npx nx run-many --target=build --all --configuration=production

Cache Management

# Clear Nx cache
npx nx reset

# Show project info
npx nx show project petfolio-business

# List projects
npx nx show projects

# List affected projects
npx nx show projects --affected

Generation Commands

Create Library

# React library
npx nx generate @nx/react:library my-lib \
  --directory=libs/my-lib \
  --tags=scope:shared

# Utility library
npx nx generate @nx/js:library my-util \
  --directory=libs/my-util \
  --tags=scope:util

Create Application

# Next.js app
npx nx generate @nx/next:application my-app \
  --directory=apps/my-app \
  --tags=scope:my-app

# React app
npx nx generate @nx/react:application my-app \
  --directory=apps/my-app

Create Component

# Component in library
npx nx generate @nx/react:component Button \
  --project=ui-component-library \
  --directory=atoms

# With story
npx nx generate @nx/react:component Button \
  --project=ui-component-library \
  --directory=atoms \
  --generateStories

Docker Commands

# Build Docker image
docker build -f apps/petfolio-business/Dockerfile -t petfolio-business .

# Run container
docker run -p 4200:4200 petfolio-business

# Run detached
docker run -d -p 4200:4200 --name petfolio petfolio-business

# View logs
docker logs -f petfolio

# Stop container
docker stop petfolio

# Remove container
docker rm petfolio

Documentation Commands

# Serve docs locally
npx nx serve petfolio-docs
# or
cd apps/petfolio-docs && mkdocs serve

# Build docs
npx nx build petfolio-docs
# or
cd apps/petfolio-docs && mkdocs build

# Deploy to GitHub Pages
cd apps/petfolio-docs && mkdocs gh-deploy

# Deploy specific version
cd apps/petfolio-docs && mike deploy 1.0.0 latest --update-aliases

# List versions
cd apps/petfolio-docs && mike list

# Set default version
cd apps/petfolio-docs && mike set-default latest

Package Management

# Install dependencies
npm install

# Install specific package
npm install --save package-name

# Install dev dependency
npm install --save-dev package-name

# Update dependencies
npm update

# Check outdated
npm outdated

# Audit security
npm audit

# Fix vulnerabilities
npm audit fix

Git Commands

# Create feature branch
git checkout -b feature/my-feature

# Commit changes
git add .
git commit -m "feat: add new feature"

# Push to remote
git push origin feature/my-feature

# Create PR (GitHub CLI)
gh pr create --title "Add new feature" --body "Description"

# View PR status
gh pr status

# Checkout PR
gh pr checkout <pr-number>

Workspace Commands

# Show Nx version
npx nx --version

# Show workspace info
npx nx report

# Migrate to latest Nx
npx nx migrate latest

# Run migrations
npx nx migrate --run-migrations

# Format code
npx nx format:write

# Check format
npx nx format:check

Storybook Commands

# Start Storybook
npx nx storybook ui-component-library

# Build Storybook
npx nx build-storybook ui-component-library

# Serve built Storybook
npx http-server libs/ui-component-library/storybook-static

CI/CD Commands

These run automatically in CI but can be run locally:

# Run all CI checks
npx nx affected:lint && \
npx nx affected:test && \
npx nx affected:build

# With parallel execution
npx nx run-many --target=lint --all --parallel=3 && \
npx nx run-many --target=test --all --parallel=2 && \
npx nx run-many --target=build --all

Utility Commands

# Print environment info
npx nx report

# List all targets
npx nx show project petfolio-business --json

# Dry run (show what would run)
npx nx affected:test --dry-run

# Skip cache
npx nx build petfolio-business --skip-nx-cache

# Verbose output
npx nx build petfolio-business --verbose

Keyboard Shortcuts (Nx Console)

When using Nx Console in VS Code:

  • Ctrl+Shift+P → "Nx: Generate"
  • Ctrl+Shift+P → "Nx: Run Target"
  • Ctrl+Shift+P → "Nx: Affected"

Command Options

Common flags across commands:

Flag Description
--help Show help
--version Show version
--verbose Verbose output
--dry-run Show what would run
--skip-nx-cache Skip cache
--parallel=N Run N tasks in parallel
--maxParallel=N Max parallel tasks
--configuration=<name> Use specific configuration
--prod Production build

Next Steps