# How to Deploy a NestJS App to Production With AI in 2026

> Deploy a NestJS app to production in 2026 without SSH, Docker, or server setup. Step-by-step guide on Kuberns with AI automation, env vars, and auto-scaling.
- **Author**: parth-kanpariya
- **Published**: 2026-04-20
- **Modified**: 2026-07-10
- **Category**: Deployment Guides
- **URL**: https://kuberns.com/blogs/deploy-nestjs-app/

---

Deploying a NestJS app to production requires two things most guides miss: binding to `process.env.PORT` in `main.ts`, and running `npm run build` before the start command. Get either wrong and the app either fails to start or is unreachable on its assigned port. NestJS compiles TypeScript into a `dist/` folder before it can run, which is exactly the step most single-command deployment platforms skip or misconfigure.

Kuberns handles both automatically: it reads your `package.json`, runs the build step, and starts your app on the correct port with zero configuration. Connect your GitHub repo, add your environment variables, and your NestJS app is live on a production HTTPS URL in under 5 minutes, with auto-scaling, monitoring, and CI/CD included. No Dockerfile, no Nginx config, no PM2 setup required.

## TL;DR

- **Build step**: NestJS compiles TypeScript to dist/ before starting. Kuberns runs this automatically
- **Port config**: main.ts must use process.env.PORT or the app will be unreachable after deploy
- **Environment vars**: DATABASE_URL, JWT_SECRET, NODE_ENV set in dashboard. Never commit secrets to your repo
- **CI/CD**: every GitHub push triggers npm run build then npm run start:prod automatically
- **TypeORM**: set synchronize: false in production. Run migrations via the start:prod script
- **Live in**: under 5 minutes from signup to a production HTTPS URL on AWS

## 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](https://kuberns.com/), 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:

```typescript
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:

```json
{
  "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:

```bash
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.

## Step-by-Step: Deploy NestJS on Kuberns

[Kuberns](https://kuberns.com/) 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](https://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](https://kuberns-blogs-media.s3.ap-south-1.amazonaws.com/kuberns-registration.png)

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](https://kuberns-blogs-media.s3.ap-south-1.amazonaws.com/environment-variable-kuberns.png)

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](https://kuberns-blogs-media.s3.ap-south-1.amazonaws.com/kuberns-ai-deploying.png)

- 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](https://kuberns-blogs-media.s3.ap-south-1.amazonaws.com/deployed-dashboard.png)

## 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`:

```typescript
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`:

```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 production | Manual / VPS | Kuberns |
|---|---|---|
| TypeScript build step | Configure CI manually | AI detects and runs automatically |
| Process manager (PM2) | Install and configure | Not needed - AI manages processes |
| Nginx reverse proxy | Manual config | Not required |
| SSL certificate | Certbot setup and renewal | Automatic |
| Environment variables | Server env files | Encrypted in dashboard |
| Auto-scaling | Manual rules | AI-driven |
| CI/CD pipeline | GitHub Actions YAML | Built-in, triggers on Git push |
| Custom domain + HTTPS | DNS config + Certbot | One-click in dashboard |
| Database migrations | Run manually on server | Automate via start:prod script |
| Crash recovery | PM2 ecosystem config | Automatic |

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

<a href="https://dashboard.kuberns.com">
  <img src="https://kuberns-blogs-media.s3.ap-south-1.amazonaws.com/deploy-on-kuberns-bannner9.png" alt="Deploy NestJS on Kuberns" />
</a>

## NestJS Deployment Platform Comparison (2026)

| Platform | Auto-detect NestJS build | Config required | Free tier | Sleeps on idle | Starting price | Auto-scaling | Best for |
|---|---|---|---|---|---|---|---|
| Kuberns | Yes - reads package.json | None | Yes ($14 credits) | No | $7/mo | AI-driven | Full-stack APIs, SaaS, enterprise NestJS |
| Heroku | Partial (needs Procfile) | Procfile required | No (removed 2022) | No | $7/mo | Manual dynos | Simple apps, legacy projects |
| Render | Yes | Build/start commands | Yes (sleeps) | Yes - 15 min | $7/mo | Rules-based | Full-stack, Heroku migrations |
| Railway | Yes | Start command | $5 trial credit | No (credits expire) | $5/mo + usage | Limited | Prototypes |
| DigitalOcean App Platform | Yes | Build/run commands | No | No | $5/mo | Rules-based | Teams with DevOps knowledge |
| AWS Elastic Beanstalk | Yes | .ebextensions config | No | No | Pay-as-you-go | Yes | Enterprise AWS teams |
| VPS (PM2 + Nginx) | Manual | PM2 + Nginx + SSL | No | No | ~$5/mo | Manual only | Full control, DevOps teams |

## Common NestJS Deployment Errors and Fixes

If you are migrating from a Node.js or Express setup, see the [complete Node.js deployment guide](https://kuberns.com/blogs/how-to-deploy-nodejs-app/) for a comparison. For full-stack apps with a React frontend alongside your NestJS API, see [how to deploy a MERN stack app on Kuberns](https://kuberns.com/blogs/deploy-mern-app/). For TypeScript-first monorepo setups, see the [T3 stack deployment guide](https://kuberns.com/blogs/deploy-t3-stack-app/). If you are migrating off Heroku, see the [full Heroku alternatives guide](https://kuberns.com/blogs/the-ultimate-guide-to-heroku-alternatives-in-2025/) for a detailed comparison.

**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.

```json
"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.

## Conclusion

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, and monitor. 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 your repo, push code, and the app is live. No sleep-on-idle behavior, no dyno limits, and no pricing that compounds quickly.

[Deploy with Agentic AI on Kuberns](https://dashboard.kuberns.com)

<a href="https://dashboard.kuberns.com" target="_blank" rel="noopener noreferrer">
  <img src="https://kuberns-blogs-media.s3.ap-south-1.amazonaws.com/deploy-on-kuberns-bannner9.png" alt="Start deploying NestJS on Kuberns" style={{ width: "100%", height: "auto" }} />
</a>

## Frequently Asked Questions on NestJS Deployment

### What is the easiest way to deploy a NestJS app in 2026?

The easiest way is using Kuberns. Connect your GitHub repo, add environment variables, and click deploy. The AI handles build, SSL, scaling, and monitoring automatically without any server configuration.

### Do I need Docker to deploy NestJS?

No. Platforms like Kuberns auto-detect NestJS and handle the build and deployment pipeline without requiring a Dockerfile.

### How do I set the port for NestJS in production?

Use process.env.PORT in your main.ts bootstrap function. Cloud platforms inject a dynamic port at runtime and your app must listen on it. Hardcoding port 3000 is the most common reason NestJS apps are unreachable after deployment.

### What NestJS version should I use in 2026?

As of July 2026, the current [@nestjs/core](https://www.npmjs.com/package/@nestjs/core) release is 11.1.28, and [@nestjs/config](https://www.npmjs.com/package/@nestjs/config) is at 4.0.4. Kuberns detects and builds against whatever NestJS version is pinned in your package.json, so upgrading your core packages does not require any changes to your deployment configuration.

### Can I deploy NestJS with a database on Kuberns?

Yes. Pass your DATABASE_URL as an environment variable in the Kuberns dashboard and your NestJS app will connect to PostgreSQL, MySQL, or MongoDB automatically.

### How long does NestJS deployment take on Kuberns?

Under 5 minutes for the first deployment. Subsequent auto-deployments on Git push take around 60 to

---
- [More Deployment Guides articles](https://kuberns.com/blogs/category/deployment-guides/1/)
- [All articles](https://kuberns.com/blogs/)