> ## 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/node

> The Node plugin for Nx provides generators for creating and managing Node.js applications and libraries within an Nx workspace.

The `@nx/node` plugin adds Node.js support to your Nx workspace. It provides generators for scaffolding Node applications and libraries, with built-in support for popular frameworks like Express, Fastify, and NestJS. Applications can be built with esbuild or webpack.

## Installation

```bash theme={null}
nx add @nx/node
```

Or install manually:

<CodeGroup>
  ```bash npm theme={null}
  npm install --save-dev @nx/node
  ```

  ```bash pnpm theme={null}
  pnpm add --save-dev @nx/node
  ```

  ```bash yarn theme={null}
  yarn add --dev @nx/node
  ```
</CodeGroup>

## What the plugin provides

<CardGroup cols={3}>
  <Card title="Generators" icon="wand-sparkles">
    Scaffold Node.js applications, libraries, and Docker configurations.
  </Card>

  <Card title="Framework support" icon="server">
    Generate Express, Fastify, and NestJS applications with optional framework boilerplate.
  </Card>

  <Card title="Docker integration" icon="box">
    Add Docker configuration to any Node.js project with the `setup-docker` generator.
  </Card>
</CardGroup>

## Generators

### application

Create a new Node.js application.

```bash theme={null}
nx generate @nx/node:application myapi
```

Specify a framework:

```bash theme={null}
# Express
nx generate @nx/node:application myapi --framework=express

# Fastify
nx generate @nx/node:application myapi --framework=fastify

# NestJS
nx generate @nx/node:application myapi --framework=nest

# No framework (plain Node.js)
nx generate @nx/node:application myapi --framework=none
```

Choose a bundler:

```bash theme={null}
# esbuild (default)
nx generate @nx/node:application myapi --bundler=esbuild

# Webpack
nx generate @nx/node:application myapi --bundler=webpack
```

### library

Create a Node.js library that can be shared across your workspace.

```bash theme={null}
nx generate @nx/node:library mylib
```

Create a publishable library:

```bash theme={null}
nx generate @nx/node:library mylib --publishable --importPath=@myorg/mylib
```

### setup-docker

Add a `Dockerfile` and Docker Compose configuration to an existing Node.js project.

```bash theme={null}
nx generate @nx/node:setup-docker --project=myapi
```

This creates a production-ready `Dockerfile` that:

* Uses a multi-stage build to keep the final image small
* Copies only the built output and required `node_modules`
* Runs the application as a non-root user

## Inferred tasks

`@nx/node` delegates build and serve targets to `@nx/js`, `@nx/esbuild`, and `@nx/webpack` depending on the chosen bundler. Tasks are inferred from the build tool's configuration file when the corresponding plugin is registered in `nx.json`.

<Tip>
  When you generate a Node application, Nx automatically configures the appropriate bundler plugin so that `build`, `serve`, and `test` tasks are available without manual configuration.
</Tip>

## Configuration examples

### project.json for an Express app (esbuild)

```json theme={null}
{
  "name": "myapi",
  "targets": {
    "build": {
      "executor": "@nx/esbuild:esbuild",
      "options": {
        "outputPath": "dist/myapi",
        "main": "myapi/src/main.ts",
        "tsConfig": "myapi/tsconfig.app.json",
        "platform": "node"
      },
      "configurations": {
        "production": {
          "minify": true
        }
      }
    },
    "serve": {
      "executor": "@nx/js:node",
      "options": {
        "buildTarget": "myapi:build"
      }
    },
    "test": {
      "executor": "@nx/jest:jest",
      "options": {
        "jestConfig": "myapi/jest.config.ts"
      }
    }
  }
}
```

### Docker setup

After running `setup-docker`, serve the application in a container:

```bash theme={null}
# Build the Docker image
docker build -f myapi/Dockerfile . -t myapi

# Run the container
docker run -p 3000:3000 myapi
```

## Running tasks

```bash theme={null}
# Build the application
nx build myapi

# Serve in development (with watch mode)
nx serve myapi

# Run unit tests
nx test myapi

# Build for production
nx build myapi --configuration=production
```

## Working with NestJS

For full NestJS support, use `@nx/nest` which extends `@nx/node` with NestJS-specific generators for modules, controllers, services, guards, pipes, and interceptors.

```bash theme={null}
nx add @nx/nest
nx generate @nx/nest:application myapi
```
