DEV Community

Sakthikumaran Navakumar
Sakthikumaran Navakumar

Posted on

The Nx Cheatsheet — Commands for Daily Development

If you have just started working with Nx — or joined a team that uses it — the CLI can feel overwhelming at first. There are dozens of commands, flags, and concepts to absorb all at once.

This cheatsheet cuts through the noise. It covers the commands you will actually use every day, organised by workflow, explained plainly. Bookmark it, come back to it, share it with your team. Complete List of CLI commands can be found here.


📋 Table of Contents

  1. What is Nx?
  2. Creating a Workspace
  3. Adding Plugins
  4. Generating Projects and Code
  5. Running and Serving Applications
  6. Running Multiple Tasks
  7. Filtering Projects with Patterns and Tags
  8. Building Projects
  9. The Affected Commands
  10. Skipping and Managing the Cache
  11. Running Tests
  12. Linting and Formatting
  13. Visualising the Dependency Graph
  14. Workspace and Project Info
  15. The Nx Daemon
  16. Quick Reference Cheat Sheet

What is Nx?

Nx is an open-source build system and monorepo toolkit. It lets you manage all your applications and shared libraries in a single repository while giving you intelligent tooling to build, test, and serve them efficiently.

Three things make Nx stand out:

  • 🧠 Smart task runner — understands your project dependency graph and only rebuilds what has actually changed
  • 🏗️ Code generation — scaffolds apps, libraries, and components using best-practice templates
  • 📊 Visualisation — interactive graph to see how all your projects connect

1. Creating a Workspace

Everything starts here. A workspace is the root container for all your applications and libraries.

# Create a new workspace interactively
npx create-nx-workspace@latest

# Create with a specific framework preset
# (react, angular, next, node, ts, empty)
npx create-nx-workspace@latest --preset=react

# Create a blank monorepo with a custom name
npx create-nx-workspace@latest --preset=empty --name=myorg

# Specify your preferred package manager (npm, yarn, pnpm)
npx create-nx-workspace@latest --packageManager=pnpm

# Add Nx to an already-existing project or monorepo
nx init
Enter fullscreen mode Exit fullscreen mode

2. Adding Plugins

Nx is plugin-driven. Plugins provide the framework-specific generators and executors for React, Angular, Node, and more. The nx add command installs a plugin and automatically runs its initialisation generator in one step — no manual wiring required.

# Install the React plugin and auto-initialize it
nx add @nx/react

# Install the Angular plugin and wire it up automatically
nx add @nx/angular
Enter fullscreen mode Exit fullscreen mode

3. Generating Projects and Code

Instead of manually creating folders and configuration files, let Nx do it for you. The nx generate (or nx g) command creates everything following best practices for your chosen framework.

# Generate a new application
nx g app <n>

# Generate a new shared library
nx g lib <n>

# Generate a component (framework-specific)
nx g component <n>

# Preview what will be generated WITHOUT writing any files
nx g app <n> --dry-run
Enter fullscreen mode Exit fullscreen mode

4. Running and Serving Applications

Nx provides a consistent interface for running your projects regardless of which framework or tooling is underneath. nx serve myapp is shorthand for nx run myapp:serve — both do the same thing.

# Start a local development server
nx serve <project>

# Run any defined target on a project
nx run <project>:<target>

# Run a target with a specific configuration (e.g. production, staging)
nx run <project>:<target>:<configuration>
Enter fullscreen mode Exit fullscreen mode

5. Running Multiple Tasks

As your monorepo grows, you need to run operations across multiple projects at once. nx run-many fans out work across your workspace in parallel. The default parallelism is 3 — increase it based on your machine's capacity.

# Run multiple targets across ALL projects in one command
nx run-many -t build test lint

# Run multiple targets on specific named projects only
nx run-many -t build test lint -p app1 app2

# Run tasks with a concurrency limit
nx run-many -t build --parallel=5

# Run with the interactive Terminal UI (new in Nx v22)
nx run-many -t build --outputStyle=tui
Enter fullscreen mode Exit fullscreen mode

6. Filtering Projects with Patterns and Tags

Instead of listing every project name manually, use glob patterns and Nx project tags to target exactly the right set of projects. Tags are labels you assign to projects in their config — for example scope:frontend or type:ui.

# Run only projects tagged with scope:frontend
nx run-many -t build --projects='tag:scope:frontend'

# Run only projects whose names end with -app
nx run-many -t build --projects='*-app'

# Mix explicit names and glob patterns
nx run-many -t test --projects='app1,app2,shared-*'

# Run on all projects, EXCLUDING e2e projects
nx run-many -t lint --exclude='*-e2e'
Enter fullscreen mode Exit fullscreen mode

7. Building Projects

Building compiles your source code and produces deployment-ready artifacts. The command is the same regardless of whether you use Webpack, Vite, or esbuild underneath.

# Build a specific project
nx build <project>

# Build using the production configuration (optimised, minified)
nx build <project> --configuration=production

# Build all projects in the workspace
nx run-many -t build
Enter fullscreen mode Exit fullscreen mode

8. The Affected Commands — Nx's Superpower

This is the feature that makes Nx genuinely transformative. Instead of rebuilding and retesting everything on every commit, Nx analyses your dependency graph and figures out exactly which projects are affected by your changes — and only runs tasks for those.

If you change a utility library, Nx identifies every app and library that depends on it and runs the target for all of them. Everything else is skipped. On a large monorepo, this can reduce CI time significantly.

# Build only projects affected by recent changes
nx affected -t build

# Test only affected projects
nx affected -t test

# Lint only affected projects
nx affected -t lint

# Run multiple targets on affected projects in one command
nx affected -t build test lint

# Determine affected projects relative to a specific branch/commit range
nx affected --base=main --head=HEAD
Enter fullscreen mode Exit fullscreen mode

9. Skipping and Managing the Cache

Nx caches the results of every task. If nothing has changed since the last run, Nx replays the cached result in milliseconds. There are times, however, when you need to bypass the cache — debugging a flaky test, verifying a fix actually works, or clearing stale output.

Refer here for How caching works

# Run a build bypassing the local cache entirely
nx build <project> --skipNxCache

# Skip cache for all projects in run-many
nx run-many -t build --skipNxCache

# Skip cache on all affected test runs
nx affected -t test --skipNxCache

# Clear the entire local cache AND daemon state
nx reset

# Clear ONLY the task cache, leave the daemon running
nx reset --only-cache

# Restart ONLY the daemon, leave the cache intact
nx reset --only-daemon
Enter fullscreen mode Exit fullscreen mode

10. Running Tests

Whether your projects use Jest, Vitest, Playwright, or Cypress, nx test and nx e2e provide a consistent interface. Combine with affected and run-many for full-scale coverage.

# Run unit tests for a specific project
nx test <project>

# Run end-to-end tests for a project
nx e2e <project>

# Run unit tests only for affected projects
nx affected -t test

# Run unit tests across ALL projects
nx run-many -t test
Enter fullscreen mode Exit fullscreen mode

11. Linting and Formatting

Keeping code quality consistent across a monorepo is hard without tooling. Nx gives every project its own lint target and provides workspace-level format commands powered by Prettier.

# Lint a specific project
nx lint <project>

# Lint only the projects affected by recent changes
nx affected -t lint

# Auto-format ALL files in the workspace using Prettier
nx format:write

# Check formatting across the workspace WITHOUT writing (perfect for CI)
nx format:check
Enter fullscreen mode Exit fullscreen mode

12. Visualising the Dependency Graph

At any point you can visualise the entire architecture of your monorepo as an interactive browser-based graph. This is invaluable for onboarding new team members, auditing architecture, and understanding the blast radius of a change.

# Open the interactive dependency graph in the browser
nx graph

# Show only the subgraph of a specific project and its dependencies
nx graph --focus=<project>

# Print the project graph as JSON to the terminal
nx graph --print

# Export the full graph to a JSON file
nx graph --file=output.json
Enter fullscreen mode Exit fullscreen mode

13. Workspace and Project Info

As your workspace grows, you need reliable ways to explore it. The nx show, nx list, and nx report commands answer the everyday questions: what exists, what is affected, what plugins are installed.

# List ALL projects in the workspace
nx show projects

# List only the projects affected by recent changes
# (modern replacement for the deprecated nx affected:apps/libs)
nx show projects --affected

# List all projects that have a specific target defined
nx show projects --with-target serve

# Show full configuration details of a specific project
nx show project <n>

# Open a rich browser view of a project's fully resolved configuration
nx show project <n> --web

# List all installed Nx plugins in the workspace
nx list

# List all generators and executors provided by a specific plugin
nx list <plugin>

# Print all installed Nx and plugin versions (essential for debugging)
nx report
Enter fullscreen mode Exit fullscreen mode

14. The Nx Daemon

The Nx Daemon is a background process that keeps your workspace's project graph in memory. Without it, every command has to re-read and re-parse your entire workspace from scratch — noticeable latency in large monorepos. In most cases it starts and stops automatically. These commands give you manual control when needed.

# Manually start the Nx daemon
nx daemon --start

# Stop the Nx daemon
nx daemon --stop
Enter fullscreen mode Exit fullscreen mode

⚡ Quick Reference Cheat Sheet

🏗️ Workspace Setup

Command What it does
npx create-nx-workspace@latest Create a new workspace
nx init Add Nx to an existing project
nx add @nx/react Add and initialize a plugin

🔧 Generate Code

Command What it does
nx g app <n> New application
nx g lib <n> New shared library
nx g component <n> New component
nx g app <n> --dry-run Preview generation without writing files

▶️ Run Tasks

Command What it does
nx serve <project> Start dev server
nx build <project> Build a project
nx test <project> Run unit tests
nx e2e <project> Run e2e tests
nx lint <project> Lint a project

🚀 Scale Across Projects

Command What it does
nx run-many -t build test lint Run multiple targets across all projects
nx run-many -t build --parallel=5 Run with concurrency control
nx run-many -t build --projects='*-app' Target projects by glob pattern
nx run-many -t build --projects='tag:scope:frontend' Target projects by tag
nx run-many -t lint --exclude='*-e2e' Exclude projects by pattern
nx affected -t build test lint Only run what is affected by your changes
nx affected --base=main --head=HEAD Affected in a PR commit range

🗄️ Cache Management

Command What it does
nx build <project> --skipNxCache Bypass cache for one task
nx reset --only-cache Clear task cache only
nx reset --only-daemon Restart daemon only
nx reset Full reset — cache + daemon

🔍 Explore & Debug

Command What it does
nx graph Open interactive dependency graph
nx graph --focus=<project> Focus graph on one project
nx show projects --affected List affected projects
nx show project <n> --web Inspect full project config in browser
nx report Check all installed plugin versions
nx format:check Check formatting (great for CI)
nx format:write Auto-format the entire workspace

Useful Links


Found this useful? Drop a ❤️ and share it with a teammate who is just getting started with Nx.

Top comments (0)