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 graphnx show projects
to see a list of all projectsnx show project <project-name>
to view an interactive project detailed viewnx 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
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
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
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:
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.
Install Nx Console for VSCodeThe official VSCode extension for Nx.
Install Nx Console for JetBrainsAvailable for WebStorm, IntelliJ IDEA Ultimate and more!
In-depth Guides
Here are some guides that give you more details based on the technology stack you're using: