> ## 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.

# nx graph

> Visualize the project dependency graph or task graph for your Nx workspace.

```bash theme={null}
nx graph [options]
```

Alias: `nx dep-graph`

`nx graph` opens an interactive visualization of your workspace's project dependency graph in the browser. You can also export the graph as JSON or HTML, filter by project, or show only affected projects.

## Options

### Output

<ParamField query="--file" type="string">
  Write the graph to a file instead of opening the browser. Supports `.json` for raw data and `.html` for a self-contained interactive page.

  ```bash theme={null}
  nx graph --file=output.json
  nx graph --file=dep-graph.html
  ```
</ParamField>

<ParamField query="--print" type="boolean">
  Print the project graph to stdout in the terminal instead of opening the browser.
</ParamField>

### View mode

<ParamField query="--view" type="string" default="projects">
  Choose whether to visualize the project graph or the task graph. Choices: `projects`, `tasks`.
</ParamField>

<ParamField query="--targets" type="string">
  The targets to show when viewing the task graph (`--view=tasks`). Accepts comma-separated values.

  ```bash theme={null}
  nx graph --view=tasks --targets=build,test
  ```
</ParamField>

### Filtering

<ParamField query="--focus" type="string">
  Highlight a single project and all of its ancestors and descendants. All other projects are dimmed.

  ```bash theme={null}
  nx graph --focus=myapp
  ```
</ParamField>

<ParamField query="--exclude" type="string">
  Comma-separated list of projects to hide from the graph.

  ```bash theme={null}
  nx graph --exclude=e2e-app,temp-lib
  ```
</ParamField>

<ParamField query="--affected" type="boolean">
  Highlight only the projects that are affected by recent changes. Requires git context (uses the same base/head logic as `nx affected`).
</ParamField>

<ParamField query="--base" type="string">
  Base git ref for computing affected projects. Implies `--affected`.
</ParamField>

<ParamField query="--head" type="string">
  Head git ref for computing affected projects. Implies `--affected`.
</ParamField>

<ParamField query="--files" type="string">
  Treat specific files as changed when computing affected projects. Implies `--affected`.
</ParamField>

<ParamField query="--uncommitted" type="boolean">
  Include uncommitted changes when computing affected projects. Implies `--affected`.
</ParamField>

<ParamField query="--untracked" type="boolean">
  Include untracked files when computing affected projects. Implies `--affected`.
</ParamField>

### Display

<ParamField query="--group-by-folder" type="boolean">
  Group projects visually by their folder path in the interactive graph.
</ParamField>

<ParamField query="--watch" type="boolean" default="true">
  Watch for workspace changes and automatically update the graph in the browser.
</ParamField>

<ParamField query="--open" type="boolean" default="true">
  Open the graph in the default browser. Set to `false` to start the server without opening.
</ParamField>

### Server

<ParamField query="--host" type="string">
  IP address to bind the graph server to. Defaults to `localhost`.
</ParamField>

<ParamField query="--port" type="number">
  Port to bind the graph server to.
</ParamField>

<ParamField query="--verbose" type="boolean">
  Print additional information about the command.
</ParamField>

## Examples

<CodeGroup>
  ```bash Open interactive graph in browser theme={null}
  nx graph
  ```

  ```bash Export graph data as JSON theme={null}
  nx graph --file=output.json
  ```

  ```bash Export as a standalone HTML page theme={null}
  nx graph --file=dep-graph.html
  ```

  ```bash Focus on a single project theme={null}
  nx graph --focus=myapp
  ```

  ```bash Show only affected projects theme={null}
  nx graph --affected --base=origin/main
  ```

  ```bash Visualize the task graph for the build target theme={null}
  nx graph --view=tasks --targets=build
  ```

  ```bash Group projects by folder theme={null}
  nx graph --group-by-folder
  ```

  ```bash Start server on a custom port without opening the browser theme={null}
  nx graph --port=4212 --open=false
  ```

  ```bash Print graph data to stdout theme={null}
  nx graph --print
  ```
</CodeGroup>

<Note>
  The `nx affected:graph` command is a deprecated alias for `nx graph --affected`. Use `nx graph --affected` instead.
</Note>

## Using the interactive graph

When the graph opens in the browser, you can:

* Click a project node to see its dependencies and dependents
* Use the sidebar to search for and filter projects
* Toggle between **Projects** and **Tasks** views
* Enable **Group by folder** to organize nodes by directory structure
* Use **Focus** to isolate a project's subgraph
* Export the current view as a PNG or JSON
