# Nx — Smart Monorepos and Fast CI for JavaScript and Beyond > Nx is a build system and monorepo tool with first-class support for JavaScript, TypeScript, Go, Python, Java, and more. It offers computation caching, affected commands, task orchestration, and distributed execution — scaling from small repos to Google-sized codebases. ## Install Save in your project root: # Nx — Smart Monorepos and Fast CI ## Quick Use ```bash npx create-nx-workspace@latest myworkspace cd myworkspace npx nx g @nx/react:app web npx nx g @nx/node:app api npx nx run-many -t build test lint npx nx affected -t build # build only projects impacted by changes ``` ## Introduction Nx (by Nrwl, now Nx) brings Google-scale monorepo techniques to everyday projects. It understands your project graph, caches every task, and runs only what changed. The same command that takes 20 minutes without Nx can finish in seconds on a warm cache. With over 29,000 GitHub stars, Nx is used by Cisco, Capital One, Walmart, and any team that feels the pain of slow monorepo CI. It supports Angular, React, Next.js, Vue, Node, NestJS, Express, Go, Rust, Python, Java, and more via plugins. ## What Nx Does Nx analyzes your project (via `nx.json` + `project.json` files) to build a dependency graph. Every task (build, test, lint, e2e) is cached by inputs — source files, environment, deps. Cache hits are reused locally or shared via Nx Cloud. `nx affected` runs tasks only on projects touched by the current PR. ## Architecture Overview ``` monorepo/ apps/web, apps/api, libs/ui, libs/auth, libs/utils | [Project Graph] derived from imports + project.json | [Task Graph] which tasks depend on which | [Execution] +-- Local cache (.nx/cache) +-- Remote cache (Nx Cloud / self-hosted) +-- Distributed (split tasks across agents) | [Affected] git diff --> only touched projects ``` ## Self-Hosting & Configuration ```jsonc // nx.json { "targetDefaults": { "build": { "cache": true, "dependsOn": ["^build"], "inputs": ["production", "^production"] }, "test": { "cache": true, "inputs": ["default", "^production"] }, "lint": { "cache": true } }, "namedInputs": { "default": ["{projectRoot}/**/*"], "production": ["default", "!{projectRoot}/**/*.spec.ts"] }, "tasksRunnerOptions": { "default": { "runner": "nx/tasks-runners/default", "options": { "cacheableOperations": ["build", "test", "lint"] } } } } ``` ```bash npx nx graph # interactive project graph npx nx affected -t test --parallel=4 npx nx reset # clear cache npx nx generate @nx/react:lib ui-components ``` ## Key Features - **Computation caching** — skip unchanged work, local + remote - **Affected commands** — run tasks only on changed projects - **Project graph** — visualize dependencies, detect cycles - **Code generators** — scaffold apps, libs, components in one command - **Remote cache (Nx Cloud)** — share hits across developers and CI - **Distributed task execution** — split tests/builds across many agents - **Polyglot** — JS/TS first-class; plugins for Go, Python, Rust, Java - **Migrations** — automated codemods when upgrading tools/versions ## Comparison with Similar Tools | Feature | Nx | Turborepo | Bazel | Lerna | pnpm workspaces | |---|---|---|---|---|---| | Caching | Yes (local+cloud) | Yes (local+cloud) | Yes | No | No | | Affected | Yes | Yes | Yes | No | No | | Code generators | Yes | No | No | No | No | | Distributed | Yes | Yes | Yes | No | No | | Languages | Many (plugins) | JS focus | Any | JS only | JS only | | Learning Curve | Moderate | Low | High | Very Low | Very Low | | Best For | JS + polyglot | JS monorepos | Huge polyglot | Legacy | Simple monorepos | ## FAQ **Q: Nx vs Turborepo — which should I use?** A: Turborepo is simpler and stays out of your way. Nx offers more (generators, plugins, richer graph, affected logic across languages) at the cost of more concepts. For large teams with custom build logic, Nx wins; for small JS monorepos, Turborepo is often enough. **Q: Do I need Nx Cloud?** A: Optional. Without it you still get local cache and affected commands. Nx Cloud adds remote cache sharing and DTE (distributed task execution) — huge for CI speed. **Q: Can I adopt Nx in an existing repo?** A: Yes. `npx nx init` adds Nx to any existing workspace without restructuring. You opt in per package. **Q: Does Nx work with pnpm?** A: Yes. Nx supports npm, yarn, pnpm, and bun. Pick whichever package manager fits your team. ## Sources - GitHub: https://github.com/nrwl/nx - Docs: https://nx.dev - Company: Nx (formerly Nrwl) - License: MIT --- Source: https://tokrepo.com/en/workflows/dc0a4fee-37be-11f1-9bc6-00163e2b0d79 Author: AI Open Source