Add Nx to an existing project

In many situations, you have an existing codebase and want to improve it with Nx using an incremental adoption approach.

Thanks to Nx's modular architecture, you can start with just Nx Core and then gradually add technology-specific plugins, CI integrations, or other capabilities as your requirements evolve.

Getting started is remarkably simple. You can add Nx to any existing project with a single command:

nx@latest init

Note: make sure you have Nx installed globally or use npx if you're in a JavaScript environment

Whether a monorepo, single project or something in between, nx init walks you through adding and configuring Nx. You can pick a minimal approach or detailed guided setup. At the end you'll have an Nx workspace ready for anything!

Next Steps

After initializing Nx, you can explore your workspace with the following commands:

  • nx graph to view an interactive graph
  • nx show projects to see a list of all projects
  • nx show project <project-name> to view an interactive project detailed view
  • nx run-many -t <target> to run tasks with Nx, e.g. nx run-many -t build

Update CI Configurations

Now that Nx is installed, you'll want to update CI configurations to leverage Nx. You can do this by changing previous commands to use nx instead.

For example, switching from pnpm commands to use nx

.github/workflows/ci.yaml
1- - run: pnpm run -r build 2- - run: pnpm run -r test 3+ - run: npx nx run-many -t test build 4

You can directly invoke package.json scripts with nx as well

.github/workflows/ci.yaml
1- - run: npm run build 2- - run: npm run test 3+ - run: npx nx build 4+ - run: npx nx test 5

View CI provider specific setups to learn more.

Nx Cloud

How do I know if I enabled Nx Cloud?

Validate Nx Cloud is enabled by checking the nx.json file for nxCloudId property. You can add Nx Cloud at any point by running the nx connect command.

After initializing Nx, you'll need to commit and push the changes to your repository.

Once your changes are pushed, you can finish setting up your workspace by clicking on the list printed to your terminal, or by visiting Nx Cloud directly and clicking "Connect an existing Nx repository"

To leverage Self Healing CI, you'll need to add the following to your CI configuration:

.github/workflows/ci.yaml
1 - run: npx nx run-many -t lint test build 2+ # Enable Self Healing CI w/ Nx Cloud 3+ - run: npx nx fix-ci 4+ if: always() 5

Empower Your Editor

Enhance your developer experience by using the Nx Console editor extension.

Visual Studio Code

Install Nx Console for VSCodeThe official VSCode extension for Nx.

IntelliJ IDEA

In-depth Guides

Here are some guides that give you more details based on the technology stack you're using: