> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/nrwl/nx/llms.txt
> Use this file to discover all available pages before exploring further.

# Add to an Existing Project

> Add Nx to any existing npm, pnpm, or yarn workspace with a single command. Start with task running and caching, then adopt more capabilities incrementally.

Nx is designed for incremental adoption. You don't need to restructure your project or migrate to a new setup — just run one command and Nx starts working alongside your existing tools.

## Add Nx with a single command

```bash theme={null}
npx nx@latest init
```

Whether you have a monorepo, a single project, or something in between, `nx init` walks you through adding and configuring Nx. At the end you'll have an Nx workspace ready to use.

### What `nx init` does

When you run `nx init` in an existing npm, pnpm, or yarn workspace, Nx:

1. **Installs the `nx` package** as a dev dependency in your root `package.json`.
2. **Creates `nx.json`** — the Nx configuration file at the root of your workspace.
3. **Picks up your existing `package.json` scripts** — every script defined in any `package.json` in the workspace is automatically available as an Nx task. No manual task configuration needed.
4. **Configures caching** — Nx infers sensible cache inputs and outputs for common tools (Vite, Jest, TypeScript, etc.) so caching works immediately.

<Note>
  You do not need to rewrite or replace your existing `package.json` scripts. Nx wraps them — calling `nx build my-app` executes the `build` script from `my-app/package.json`, equivalent to running `npm run build` inside that directory.
</Note>

## After initializing

Once `nx init` completes, try these commands:

```bash theme={null}
nx build <project-name>      # Run a task
nx build <project-name>      # Run again - instant cache hit
nx run-many -t build test    # Run tasks across all projects
nx graph                     # Visualize project dependencies
```

## Incremental adoption path

Nx is modular — you can adopt as much or as little as you need. A typical adoption progression looks like this:

<Steps>
  <Step title="Start with task running and caching">
    After `nx init`, every `package.json` script is available as an Nx task with local caching. No further configuration is required.

    ```bash theme={null}
    nx build my-app
    nx test my-lib
    ```
  </Step>

  <Step title="Add Nx plugins for your tech stack">
    Nx plugins for React, Angular, Node, Vite, Jest, and others add:

    * Precise cache input/output configuration (so cache invalidation is accurate)
    * Code generators for scaffolding new projects, components, and configurations
    * Inferred tasks from tool config files (e.g., a `vite.config.ts` automatically becomes a `build` target)

    ```bash theme={null}
    nx add @nx/react
    nx add @nx/vite
    ```
  </Step>

  <Step title="Enable remote caching">
    Connect to Nx Cloud so cache hits are shared across your team and CI:

    ```bash theme={null}
    nx connect
    ```

    Once connected, a build that passes on CI will never need to run again locally. Any developer or CI agent that runs the same task with the same inputs gets a cache hit.
  </Step>

  <Step title="Use affected commands in CI">
    In your CI pipeline, replace full builds with affected builds to only run tasks impacted by changed files:

    ```bash theme={null}
    nx affected -t build test lint
    ```

    Nx compares your branch to the base branch, builds the project graph, and determines exactly which projects are affected.
  </Step>
</Steps>

## In-depth adoption guides

<CardGroup cols={2}>
  <Card title="Migrate to Nx" icon="folder-open" href="/guides/migrate-to-nx">
    Step-by-step guide for migrating from Lerna, Turborepo, or a plain npm/pnpm/yarn workspace.
  </Card>

  <Card title="Angular plugin" icon="angular" href="/reference/plugins/angular">
    Migrate an existing Angular CLI project to Nx with the automated migration command.
  </Card>

  <Card title="Set up CI" icon="check-circle" href="/guides/ci-setup">
    Connect Nx to GitHub Actions, GitLab, Azure, or any other CI provider.
  </Card>

  <Card title="Nx plugins" icon="plug" href="/concepts/nx-plugins">
    Add plugins for your tech stack to unlock auto-configured tasks, generators, and more.
  </Card>
</CardGroup>
