DeployxaDocs Portal
CLI v1.0.4
Deploy NestJS Enterprise API
Framework guide · NestJS

Deploy a NestJS API

NestJS compiles TypeScript to dist/ at build time and runs as a Node.js process. Run your Prisma or TypeORM migrations before the release takes traffic, and the API is served over HTTPS with health checks.

Prerequisites

  • A NestJS 10 or newer project (as generated by nest new) with nest-cli.json and a lockfile.
  • The default scripts: "build": "nest build" and "start:prod": "node dist/main".
  • @nestjs/cli available at build time (it is a devDependency in generated projects).

How Deployxa detects NestJS

nest-cli.json next to package.json identifies a NestJS project on Node.js 20. Set the commands below; the generic Node.js default start command (npm start) runs nest start, which is meant for development.

SettingValue
Wizard presetNode.js API
Build commandnpm run build
Start commandnode dist/main.js
Port3000

Required config

ts
// src/main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.enableCors({ origin: process.env.CORS_ORIGIN?.split(',') ?? false });
  app.enableShutdownHooks();                       // close DB pools on redeploy
  await app.listen(Number(process.env.PORT) || 3000, '0.0.0.0');
}
bootstrap();

Add a cheap endpoint the health check and your monitoring can hit, for example a @Get('health') handler that returns { ok: true }, or @nestjs/terminus if you want database checks.

Environment variables

KeyPurposeExample
DATABASE_URLDatabase connection stringpostgresql://…
PORTListen port3000
NODE_ENVRuntime modeproduction
JWT_SECRETExample app secret, read with @nestjs/configa long random string

Read them with @nestjs/config (ConfigModule.forRoot({ isGlobal: true })). Variables set in Deployxa are real process environment variables, so no .env file is needed in production.

Databases and migrations

In the wizard's Configure step, set Database to PostgreSQL. The connection string is injected into the app as DATABASE_URL, so nothing needs to be committed. Choose SQLite only for small apps: it lives on a persistent volume and has no server.

Prisma

json
{
  "scripts": {
    "build": "prisma generate && nest build",
    "start:prod": "prisma migrate deploy && node dist/main.js"
  }
}

Set the start command to npm run start:prod. Keep prisma in dependencies so the CLI exists at runtime. If migrate deploy fails the process exits, the release fails its health check, and the previous release keeps serving traffic.

TypeORM

Set migrationsRun: true with synchronize: false in the TypeORM options, or run typeorm migration:run -d dist/data-source.js before node dist/main.js.

Deploy

From the dashboard

  1. 1
    Source

    Open Dashboard → Projects → New project (/dashboard/projects/new). Pick the GitHub repository and branch, or upload a .zip archive of the project.

  2. 2
    Configure

    Leave the framework preset on Auto-detect or choose Node.js API. Check the fields under advanced settings:

    • Build command: npm run build
    • Root directory: ./, or the sub-folder that holds the app in a monorepo
    • Database: PostgreSQL
  3. 3
    Environment

    Add your variables in the table, or paste a whole .env file into the Bulk / .env tab.

  4. 4
    Deploy

    Start the deploy and watch the build log. When the release passes its health check it is served over HTTPS on its Deployxa URL.

  5. 5
    Confirm the start command and port

    Open the project's Environment Canvas tab and select the web service. Set Start Command to node dist/main.js. Set Internal Port to 3000 so it matches the port your app listens on. Save and redeploy if you changed anything.

From the CLI

shell
$ npm install -g @deployxa/cli
$ deployxa login
$ cd my-app
$ deployxa link            # pick an existing project, or skip: deploy creates one
$ deployxa env set JWT_SECRET "change-me"
$ deployxa deploy
$ deployxa logs --live     # stream build and runtime logs
$ deployxa open            # open the live URL

If the folder is not linked, deployxa deploy creates a project named after the folder and links it (the link is saved in .deployxa/config.json). Later runs deploy the linked project. deployxa status shows the latest deployment and deployxa rollback previous returns to the release before it.

Warning: deployxa deploy packages the folder exactly as it is on disk; it does not read .gitignore. Delete local node_modules, virtualenvs, build output and real .env files first, or deploy from a clean clone. Set secrets with deployxa env set instead of shipping them in the archive.

Custom domain

Go to Dashboard → Domains, choose Connect a domain you already own and pick this project. Deployxa then shows the DNS records to create at your DNS provider:

RecordUse it forValue
AAn apex domain such as example.com85.17.244.184 (DNS only on Cloudflare)
CNAMEA subdomain such as www or appcname.deployxa.com (DNS only on Cloudflare)
TXTOnly when a CDN or proxy (for example Cloudflare orange-cloud) hides the origin recordHost _deployxa-challenge.<your-domain>, value deployxa-verification=…

DNS changes can take several minutes to propagate; use Retry verification once they have. A Let's Encrypt certificate is issued after the domain verifies. From a linked folder you can do the same with the CLI:

shell
$ deployxa domains add app.example.com
$ deployxa dns             # Waiting → Verified → SSL Active
$ deployxa domains list

Common errors and fixes

SymptomFix
Error: Cannot find module '/app/dist/main'The build did not run or emitted elsewhere. Check the build command is npm run build and tsconfig.build.json outputs to dist.
nest: not found during buildInstall dev dependencies at build time; @nestjs/cli is a devDependency.
@prisma/client did not initialize yetRun prisma generate in the build script.
Health check failsListen on 0.0.0.0 and process.env.PORT, and match Internal Port.
Release hangs on startA migration is waiting on a lock or the database is unreachable; check DATABASE_URL and the runtime log.

Start with deployxa logs --live (or the deployment's log view in the dashboard): the build log shows dependency and compile failures, the runtime log shows crashes and bind errors. See also Troubleshooting.