Skip to main content

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.

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

nx add @nx/node
Or install manually:
npm install --save-dev @nx/node

What the plugin provides

Generators

Scaffold Node.js applications, libraries, and Docker configurations.

Framework support

Generate Express, Fastify, and NestJS applications with optional framework boilerplate.

Docker integration

Add Docker configuration to any Node.js project with the setup-docker generator.

Generators

application

Create a new Node.js application.
nx generate @nx/node:application myapi
Specify a framework:
# 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:
# 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.
nx generate @nx/node:library mylib
Create a publishable library:
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.
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.
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.

Configuration examples

project.json for an Express app (esbuild)

{
  "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:
# Build the Docker image
docker build -f myapi/Dockerfile . -t myapi

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

Running tasks

# 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.
nx add @nx/nest
nx generate @nx/nest:application myapi

Build docs developers (and LLMs) love