Nodevisor Docs
Services

Next.js

Deploy Next.js applications with automatic builds and Traefik routing.

Overview

The Nextjs service deploys Next.js applications with automatic Docker image building and Traefik integration. It extends the Web base class and uses NodeBuilder — identical to NodeWeb in implementation.

Use Nextjs instead of NodeWeb when you want semantic clarity in your cluster configuration. Both classes produce the same Docker image build pipeline and routing setup.

Quick Start

import { DockerCluster, Traefik, Nextjs } from '@nodevisor/docker';

const cluster = new DockerCluster({ name: 'production', ... });

const traefik = new Traefik({
  ssl: { email: 'ops@example.com', redirect: true },
});

cluster.addDependency(traefik);

cluster.addDependency(new Nextjs({
  name: 'web',
  appDir: './apps/web',
  domains: ['www.example.com'],
  port: 3000,
  proxy: traefik,
}));

Configuration

NextjsConfig

OptionTypeDefaultDescription
namestringrequiredService name
domainsstring[]requiredDomains to route to this service
proxyWebProxy | WebProxyDependencyrequiredReverse proxy for routing (e.g., a Traefik instance)
portnumber3000Application port inside the container
appDirstring''Path to the Next.js app directory in the monorepo
tagsstring[]undefinedDocker image tags
artifactsArtifact[]undefinedAdditional files to copy into the production image
builderNodeBuilderAuto-createdCustom builder (overrides appDir, tags, artifacts)
imagestringBuilt from sourceDocker image (skip building if set)
environmentRecord<string, string>undefinedEnvironment variables

See the NodeWeb documentation for details on Artifact, NodeBuilder options, and Traefik integration — the configuration is identical.

Differences from NodeWeb

Nextjs and NodeWeb share the same implementation. The separate class exists for:

  • Semantic clarity — Makes it obvious which services are Next.js apps vs generic Node.js APIs
  • Future extensibility — Next.js-specific defaults can be added without affecting NodeWeb

Usage with DockerCluster

import {
  DockerCluster, DockerNode, ClusterUser,
  Traefik, Postgres, NodeWeb, Nextjs, DockerRegistry,
} from '@nodevisor/docker';

const cluster = new DockerCluster({
  name: 'production',
  nodes: [new DockerNode({ host: '10.0.0.1' })],
  users: [new ClusterUser({ username: 'root', privateKeyPath: '~/.ssh/id_ed25519' })],
  registry: new DockerRegistry({
    server: 'ghcr.io',
    username: 'myorg',
    password: process.env.REGISTRY_TOKEN!,
  }),
});

const traefik = new Traefik({
  ssl: { email: 'ops@example.com', redirect: true },
});

cluster.addDependency(traefik);

// API server
cluster.addDependency(new NodeWeb({
  name: 'api',
  appDir: './apps/api',
  domains: ['api.example.com'],
  port: 4000,
  proxy: traefik,
}));

// Next.js frontend
cluster.addDependency(new Nextjs({
  name: 'web',
  appDir: './apps/web',
  domains: ['www.example.com'],
  port: 3000,
  proxy: traefik,
  environment: {
    NEXT_PUBLIC_API_URL: 'https://api.example.com',
  },
}));

await cluster.deploy();

On this page