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

> Scaffold or update source code using a generator from an installed Nx plugin.

```bash theme={null}
nx generate <generator> [options]
```

Alias: `nx g`

`nx generate` runs a generator to create, modify, or delete files in your workspace. Generators are provided by Nx plugins (e.g., `@nx/react`, `@nx/js`) and can also be defined locally in your workspace.

## Arguments

<ParamField path="generator" type="string" required>
  The generator to run, in the format `collection:generator` (e.g., `@nx/react:application`) or just `generator` if the collection can be inferred.
</ParamField>

## Options

<ParamField query="--dry-run" type="boolean" default="false">
  Preview the file changes that would be made without actually writing them to disk. Alias: `-d`. Also enabled by setting `NX_DRY_RUN=true`.
</ParamField>

<ParamField query="--interactive" type="boolean" default="true">
  When `false`, disables interactive input prompts for generator options. All required options must be provided as flags. Also controlled by `NX_INTERACTIVE=false`.
</ParamField>

<ParamField query="--quiet" type="boolean">
  Hides logs from file system operations (e.g., `CREATE package.json`). Cannot be used together with `--verbose`.
</ParamField>

<ParamField query="--verbose" type="boolean">
  Prints additional information about the generation process, including stack traces on error. Cannot be used together with `--quiet`.
</ParamField>

## Listing available generators

Use `nx list` to discover generators from installed plugins:

```bash theme={null}
# List all installed plugins and their generators
nx list

# List generators for a specific plugin
nx list @nx/react
nx list @nx/js
```

To see the options for a specific generator, pass `--help` after the generator name:

```bash theme={null}
nx g @nx/react:application --help
nx g @nx/js:library --help
```

## Examples

<CodeGroup>
  ```bash Generate a React application theme={null}
  nx generate @nx/react:application myapp
  ```

  ```bash Generate a JS library with a custom directory theme={null}
  nx generate @nx/js:library mylib --directory=libs/shared/mylib
  ```

  ```bash Preview changes without writing files theme={null}
  nx generate @nx/react:component MyButton --project=myapp --dry-run
  ```

  ```bash Generate without interactive prompts theme={null}
  nx generate @nx/react:application myapp --interactive=false --style=css
  ```

  ```bash Using the g shorthand alias theme={null}
  nx g @nx/angular:service my-service --project=myapp
  ```
</CodeGroup>

<Note>
  Generator options vary by plugin and generator. Always check the generator's schema with `--help` before running.
</Note>

## Workspace generators

You can define your own generators locally in `tools/generators`. Run them by their name without a collection prefix:

```bash theme={null}
nx generate my-local-generator --name=foo
```

Or with the local plugin collection:

```bash theme={null}
nx g @my-org/workspace-plugin:my-generator
```
