Published on · Updated on: · By Parth Kanpariya

- 9 min read

How to Deploy a NestJS App in 2026 (Complete Step-by-Step Guide)

img of How to Deploy a NestJS App in 2026 (Complete Step-by-Step Guide)

✨ Summarize this content with AI

You have built a NestJS app. It runs perfectly on localhost. Now you need it live in production, with HTTPS, environment variables wired correctly, a database connected, and deployments that trigger automatically on every Git push.

If you have ever tried the manual route, you know how much there is to set up. A Linux server, Node.js installed on it, PM2 to keep the process alive, Nginx configured as a reverse proxy, Certbot fighting you over SSL, and a CI/CD pipeline stitched together from GitHub Actions YAML. That gap between working locally and running in production can swallow an entire day before anything is actually live.

This guide covers the fastest path from your NestJS app to a live production URL, with the specific code changes most developers miss, a section on full-stack deployments with TypeORM and PostgreSQL, and a complete comparison of every major platform so you can pick the right one for your use case.

What Makes NestJS Deployment Different from Plain Node.js

NestJS is a TypeScript-first, opinionated framework that compiles your code before running it. This introduces two requirements that plain Express apps do not have.

Your app must be built before it starts. NestJS outputs compiled JavaScript into a dist/ folder. The start command in production is node dist/main.js, not node server.js. If your deployment platform tries to run your TypeScript source directly, the app will not start.

Your build step must run before the start step. Every deployment platform needs to know: run npm run build first, then run npm run start:prod.

On Kuberns, the AI reads your package.json and detects this automatically. You do not have to configure a build pipeline, write a Procfile, or specify anything manually.

Prerequisites: Prepare Your NestJS App for Production

These two changes take less than five minutes and prevent the most common deployment failures.

1. Bind to process.env.PORT in main.ts

This is the number one reason NestJS apps fail silently in the cloud. Every platform injects a dynamic port via the PORT environment variable. Your app must listen on that port.

Open src/main.ts and update your bootstrap function:

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

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  
  // Enable CORS if your frontend is on a separate domain
  app.enableCors();
  
  // Always use process.env.PORT in production
  const port = process.env.PORT || 3000;
  await app.listen(port);
  
  console.log(`Application running on port ${port}`);
}
bootstrap();

If you hardcode await app.listen(3000), the platform assigns a different port and your app becomes unreachable.

2. Confirm Your package.json Scripts

Kuberns AI reads your scripts block to determine the build and start commands. Your package.json should look like this:

   {
  "scripts": {
    "build": "nest build",
    "start": "node dist/main",
    "start:dev": "nest start --watch",
    "start:prod": "node dist/main"
  },
  "engines": {
    "node": ">=20.0.0"
  }
}

The build and start scripts are all Kuberns needs. No Procfile. No Dockerfile. No additional configuration.

3. Push Your Code to GitHub

Kuberns deploys directly from your repository. If your project is not on GitHub yet:

   git init
git add .
git commit -m "Initial NestJS app"
git branch -M main
git remote add origin https://github.com/yourusername/your-nestjs-app.git
git push -u origin main

That is the complete prerequisite list. No Docker image, no YAML config, no CLI tools to install.

Deploy your NestJS app on Kuberns

Step-by-Step: Deploy NestJS on Kuberns

Kuberns is an agentic AI cloud platform built on AWS. It auto-detects your NestJS framework, runs the TypeScript build, starts your app, handles SSL, and manages auto-scaling without any configuration from you.

Step 1: Sign Up and Create an Account

Go to kuberns.com and sign up with your Google or GitHub account. New accounts include free credits to deploy and test your first app at no cost.

Step 2: Connect Your GitHub Repository

On the “Create Service” page, connect your GitHub account and select your NestJS repository.

Connect GitHub to Kuberns

Kuberns AI automatically scans your package.json and detects:

  • Framework: NestJS (TypeScript)
  • Build command: npm run build
  • Start command: npm run start:prod
  • Node.js version from the engines field

You do not select any of this manually. The AI reads it and configures the pipeline for you.

“Other platforms require you to specify build commands, runtime versions, and start commands in a separate configuration file. On Kuberns, the AI infers all of it from your package.json.”

Step 3: Add Environment Variables

Navigate to the Environment tab and add your production secrets.

Environment variables on Kuberns

For a typical NestJS app you will add variables like:

  • DATABASE_URL — your PostgreSQL or MySQL connection string
  • JWT_SECRET — your token signing secret
  • NODE_ENV — set to production
  • Any third-party API keys your app uses

You can add them one by one or click “Upload .env file” to import your local .env at once. Kuberns encrypts them and injects them securely at runtime. Never commit secrets to your repository.

Step 4: Click Deploy

Click the Deploy button and watch the real-time log stream as Kuberns handles everything:

Kuberns AI deploying NestJS app

  • Clones your repository from GitHub
  • Runs npm ci to install all dependencies cleanly
  • Runs npm run build to compile TypeScript to the dist/ folder
  • Starts your app with npm run start:prod
  • Provisions compute on AWS in your chosen region
  • Issues an SSL certificate automatically
  • Assigns a live HTTPS URL to your application
  • Enables monitoring and auto-scaling with zero configuration

Your NestJS app is live in under five minutes. Every subsequent push to your connected GitHub branch triggers an automatic redeploy. No GitHub Actions workflow needed.

Kuberns deployment dashboard

Deploying NestJS with TypeORM and PostgreSQL

Most NestJS apps use TypeORM or Prisma with a relational database. Here is what you need to handle for a production deployment.

Configure TypeORM for Production

Avoid hardcoding database credentials. Use environment variables in your app.module.ts:

   import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';

@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'postgres',
      url: process.env.DATABASE_URL,
      entities: [__dirname + '/**/*.entity{.ts,.js}'],
      synchronize: false, // Always false in production
      ssl: process.env.NODE_ENV === 'production'
        ? { rejectUnauthorized: false }
        : false,
    }),
  ],
})
export class AppModule {}

Set synchronize: false in production. Use TypeORM migrations instead. Set ssl: { rejectUnauthorized: false } when connecting to managed databases like AWS RDS or Supabase.

Add DATABASE_URL to Kuberns

In the Kuberns dashboard, add your DATABASE_URL environment variable. The format for PostgreSQL is:

   postgresql://username:password@host:5432/database_name

Kuberns injects it securely. Your NestJS app reads it at runtime via process.env.DATABASE_URL.

Running Migrations on Deploy

For TypeORM migrations, add a migration script to your package.json:

   {
  "scripts": {
    "migration:run": "typeorm migration:run -d dist/data-source.js",
    "start:prod": "npm run migration:run && node dist/main"
  }
}

This runs pending migrations automatically every time your app starts in production.

What Kuberns Handles That You Do Manually on Other Platforms

What NestJS needs in productionManual / VPSKuberns
TypeScript build stepConfigure CI manuallyAI detects and runs automatically
Process manager (PM2)Install and configureNot needed — AI manages processes
Nginx reverse proxyManual configNot required
SSL certificateCertbot setup and renewalAutomatic
Environment variablesServer env filesEncrypted in dashboard
Auto-scalingManual rulesAI-driven
CI/CD pipelineGitHub Actions YAMLBuilt-in, triggers on Git push
Custom domain + HTTPSDNS config + CertbotOne-click in dashboard
Database migrationsRun manually on serverAutomate via start:prod script
Crash recoveryPM2 ecosystem configAutomatic

Kuberns also fully supports NestJS-specific patterns including WebSocket gateways, background job workers using Bull, microservices over TCP or Redis transport, and GraphQL APIs.

Deploy NestJS on Kuberns

NestJS Deployment Platform Comparison (2026)

PlatformAuto-detect NestJS buildConfig requiredFree tierSleeps on idleStarting priceAuto-scalingBest for
KubernsYes — reads package.jsonNoneYes ($14 credits)No$7/moAI-drivenFull-stack APIs, SaaS, enterprise NestJS
HerokuPartial (needs Procfile)Procfile requiredNo (removed 2022)No$7/moManual dynosSimple apps, legacy projects
RenderYesBuild/start commandsYes (sleeps)Yes — 15 min$7/moRules-basedFull-stack, Heroku migrations
RailwayYesStart command$5 trial creditNo (credits expire)$5/mo + usageLimitedPrototypes
DigitalOcean App PlatformYesBuild/run commandsNoNo$5/moRules-basedTeams with DevOps knowledge
AWS Elastic BeanstalkYes.ebextensions configNoNoPay-as-you-goYesEnterprise AWS teams
VPS (PM2 + Nginx)ManualPM2 + Nginx + SSLNoNo~$5/moManual onlyFull control, DevOps teams

Common NestJS Deployment Errors and Fixes

Build fails with “nest: command not found” Your @nestjs/cli is in devDependencies and not installed in production. Fix: Move it to dependencies, or add npm install --include=dev as a pre-build step.

   "dependencies": {
  "@nestjs/cli": "^10.0.0"
}

App starts but immediately crashes Usually a missing environment variable. Check the Kuberns logs tab for TypeError: Cannot read properties of undefined. Add the missing variable to the Environment section and redeploy.

Port binding error on startup Your main.ts is hardcoding a port. Replace await app.listen(3000) with await app.listen(process.env.PORT || 3000).

TypeORM cannot connect to database Check that DATABASE_URL is set correctly in Kuberns environment variables. For AWS RDS, ensure the security group allows inbound connections from Kuberns IP ranges.

dist/ folder not found Your build step is not running. Confirm that your package.json has a "build": "nest build" script. Kuberns triggers this automatically when it detects a NestJS app.

Why Developers Choose Kuberns for NestJS

NestJS is used by engineering teams building enterprise APIs, SaaS backends, and microservice architectures. These teams cannot afford deployments that take hours or infrastructure that requires a dedicated DevOps engineer to manage.

Kuberns handles the full deployment lifecycle — build, deploy, scale, monitor — so the team stays focused on the product. You push code, Kuberns ships it. Auto-scaling handles traffic spikes. Built-in monitoring catches issues before users do. And costs stay 40% lower than direct AWS because the AI continuously optimises resource allocation.

For teams migrating off Heroku, Kuberns is the closest experience to the original Heroku magic — connect repo, push code, app is live — but without the sleep-on-idle behavior, the dyno limits, or the pricing that compounds quickly.

Deploy your NestJS app on Kuberns today — your first deployment is free.

Start deploying NestJS on Kuberns

FAQ

Can I deploy NestJS microservices on Kuberns?

Yes. Deploy each service as a separate Kuberns project. Connect services via environment variables (internal URLs). The AI scales each service independently based on load.

Does Kuberns support NestJS with Prisma?

Yes. Add your DATABASE_URL to the environment variables, and your Prisma client will connect automatically. For migrations, run npx prisma migrate deploy in your start:prod script.

Can I use a custom domain with my NestJS app?

Yes. In the Kuberns dashboard, go to Domains and add your domain. Point your DNS A record to the provided IP. Kuberns issues and renews the SSL certificate automatically.

What Node.js version does Kuberns use for NestJS?

Kuberns reads the engines field from your package.json. If not specified, it defaults to the latest LTS release. NestJS 10+ requires Node.js 16 or higher. Recommend specifying "node": ">=20.0.0".

Is Kuberns suitable for a production NestJS SaaS app?

Yes. Kuberns is built on AWS infrastructure with auto-scaling, monitoring, encrypted environment variables, and custom domain support. It is production-ready from day one.

How does Kuberns compare to Heroku for NestJS?

Kuberns auto-detects the NestJS build pipeline without a Procfile. It does not sleep on idle, includes CI/CD on Git push, and costs less at scale. See our full Heroku alternatives guide for a detailed comparison.