generate

Runs a generator that creates and/or modifies files based on a generator from a collection.

Usage

nx generate <collection:generator>
nx g <generator>

Install nx globally to invoke the command directly using nx, or use npx nx, yarn nx, or pnpx nx.

Examples

Generate a new Angular application:

nx generate @nx/angular:app myapp
Nx 15 and lower use @nrwl/ instead of @nx/

Generate a new React application:

nx generate @nx/react:app myapp
Nx 15 and lower use @nrwl/ instead of @nx/

Generate a new web component application:

nx generate @nx/web:app myapp
Nx 15 and lower use @nrwl/ instead of @nx/

Generate a new Node application:

nx generate @nx/node:app myapp
Nx 15 and lower use @nrwl/ instead of @nx/

Generate a new Angular library application:

nx generate @nx/angular:library mylibrary
Nx 15 and lower use @nrwl/ instead of @nx/

Generate a new React library application:

nx generate @nx/react:library mylibrary
Nx 15 and lower use @nrwl/ instead of @nx/

Generate a new Node library application:

nx generate @nx/node:library mylibrary
Nx 15 and lower use @nrwl/ instead of @nx/

Options

defaults

Default: false

When true, disables interactive input prompts for options with a default.

dryRun

Default: false

When true, preview the changes without updating files.

force

Default: false

When true, forces overwriting of existing files.

interactive

Default: true

When false, disables interactive input prompts.

help

Show help and display available generators in the default collection.

version

Show version number