Skip to main content
Nx is designed for incremental adoption. You can add it to any existing codebase with a single command and start with just task caching, then gradually add plugins, CI integrations, and distribution.

Add Nx to an existing project

Run the following command in the root of any existing project or monorepo:
The init command walks you through an interactive setup that:
  • Detects your package manager and workspace structure
  • Identifies existing scripts in package.json files
  • Asks which scripts to cache and what their output directories are
  • Creates nx.json with sensible defaults
  • Optionally connects to Nx Cloud for remote caching
After initialisation, try these commands:

What Nx detects and configures automatically

When you run nx init, Nx inspects your repository and configures:
Nx reads package.json files across the workspace to discover projects and their names. If project.json files are present, those take precedence.
Scripts defined in each package.json become Nx tasks. Nx infers dependsOn relationships (for example, build depends on upstream build) from common patterns and from Nx plugin inference rules.
Nx creates default inputs (source files and package.json) and asks you to specify outputs (build directories) for each cacheable task during setup.
If your projects use supported tools (Vite, Jest, ESLint, Playwright, etc.), the corresponding Nx plugin can be added to infer task configuration automatically — removing manual config duplication.

Migrating from specific tools

Lerna workspaces are npm/yarn workspaces underneath. Run:
Nx detects the workspaces field in the root package.json and discovers all packages. Lerna’s lerna.json is not removed; Nx and Lerna can coexist, letting you migrate incrementally.To replace Lerna’s task orchestration with Nx:
Nx affected is more accurate than Lerna’s --since flag because it uses the full project dependency graph rather than file ownership alone.

Incremental migration strategy

You don’t need to adopt every Nx feature at once.
1

Start with caching only

Run npx nx@latest init and answer the setup questions. You immediately get local task caching with no other changes to your workflow.
2

Add remote caching

Run npx nx@latest connect to link your workspace to Nx Cloud. Cache hits are now shared across your team and CI pipeline.
3

Add plugins for your tech stack

Nx plugins for React, Angular, Node, Vite, Jest, and others can infer task configuration from existing tool config files — reducing the amount of configuration you manage manually.
4

Set up CI with affected commands

Update your CI pipeline to use nx affected so only changed projects are tested and built on each pull request.
5

Enable distributed task execution

Add Nx Agents to your CI configuration to parallelize tasks across multiple machines.

Keeping Nx updated with nx migrate

Use nx migrate to update Nx and all @nx/* packages together. Never update them manually — version mismatches cause subtle errors.

Standard update process

1

Generate the migration plan

This updates package.json and generates a migrations.json file listing the code migrations to apply. No files other than package.json are changed at this point.
2

Install updated dependencies

3

Apply code migrations

This runs the scripts in migrations.json, updating configuration files and source code to match the new versions. All changes are left unstaged for you to review.
4

Clean up

Review and commit the changes, then delete migrations.json.
Update one major version at a time. Jumping multiple major versions in a single nx migrate may skip intermediate migrations and leave your workspace in an inconsistent state. This is especially important for Angular workspaces, where it is a hard requirement.

Updating community plugins

Community plugins are updated separately:
To list all installed plugins:

Advanced migration options

Reverting a failed migration

Run migrations on a clean git branch so you can revert easily: