# How to Deploy a NestJS Application to Production in 2026

> This is the fastest way to deploy a NestJS app to production in 2026 with GitHub, env vars, build scripts, SSL, database setup, and Kuberns agentic AI.
- **Author**: parth-kanpariya
- **Published**: 2026-04-20
- **Modified**: 2026-09-07
- **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 helps with both steps: it reads your `package.json`, runs the build step, and starts your app on the correct port through an agentic AI deployment workflow. Connect your GitHub repo, add your environment variables, and move your NestJS app toward a production HTTPS URL with scaling, monitoring, and CI/CD from one dashboard.

## 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
- **Deployment path**: connect GitHub, add environment variables, review the detected build settings, and deploy to a production HTTPS URL

## 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 agentic AI deployment workflow reads your `package.json` and detects the build path. You can deploy without manually assembling a build pipeline first.

## 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 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 give Kuberns the key signals it needs for deployment. Most standard NestJS apps do not need a custom Procfile or Dockerfile to start.

### 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 for the Kuberns path: a production-ready NestJS app, a valid build script, a start command, and a GitHub repository.

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

[Kuberns](https://kuberns.com/) is an agentic AI platform for deployment. It detects your NestJS framework, runs the TypeScript build, starts your app, handles SSL, and helps manage scaling with less manual setup.

### Step 1: Sign Up and Create an Account

Go to [kuberns.com](https://kuberns.com/) and sign up with your Google or GitHub account. Kuberns offers a Trial Option, and paid plans start at $7.

### 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 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 can review these detected settings before deployment instead of configuring the full pipeline from scratch.

> Other platforms may require you to specify build commands, runtime versions, and start commands in a separate configuration file. On Kuberns, the agentic AI deployment workflow infers the common NestJS setup 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 runs the deployment workflow:

![Kuberns 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`
- Issues an SSL certificate automatically
- Assigns a live HTTPS URL to your application
- Enables monitoring and scaling from the dashboard

Once deployment completes, your NestJS app is available on a production HTTPS URL. Every subsequent push to your connected GitHub branch can trigger an automatic redeploy.

![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 | Detected from package.json |
| Process manager (PM2) | Install and configure | Managed deployment workflow |
| Nginx reverse proxy | Manual config | Handled by the platform path |
| SSL certificate | Certbot setup and renewal | Automatic |
| Environment variables | Server env files | Encrypted in dashboard |
| Scaling | Manual rules | Managed from the dashboard |
| 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 | Can be automated via start:prod script |
| Crash recovery | PM2 ecosystem config | Automatic |

Kuberns also supports common NestJS 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 | NestJS build support | Config required | Trial/free option | Sleeps on idle | Starting price | Scaling | Best for |
|---|---|---|---|---|---|---|---|
| Kuberns | Reads package.json | Low | Trial Option | No | From $7/mo | Managed from dashboard | Full-stack NestJS apps with less manual setup |
| 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 apps and 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 comfortable with cloud settings |
| 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/heroku-alternatives/) 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 APIs, SaaS backends, and microservice architectures. These teams need a deployment path that respects how NestJS actually works: TypeScript build first, production start command second, environment variables, database connectivity, and reliable process supervision.

Kuberns helps with the full deployment lifecycle: build, deploy, scale, and monitor. The team stays focused on the product while the agentic AI deployment workflow reads the repository, detects the NestJS build path, runs the production command, and keeps deployment settings in one place.

For teams migrating off Heroku or moving beyond a manual VPS, Kuberns gives a familiar GitHub-connected deployment flow without making developers assemble every production setting by hand.

[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 agentic AI deployment workflow helps with build setup, SSL, scaling, and monitoring without manual server configuration.

### Do I need Docker to deploy NestJS?

No. Platforms like Kuberns can detect NestJS and handle the build and deployment pipeline for many standard NestJS apps without making Docker the first step.

### 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 can connect to PostgreSQL, MySQL, or MongoDB at runtime.

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

A simple NestJS app can usually be deployed quickly once the GitHub repository, build script, start script, and environment variables are ready. Build time depends on the project size, dependency install time, and database setup.

### Does Kuberns support NestJS microservices?

Yes. You can deploy NestJS microservices as separate services on Kuberns and connect them through environment variables or service URLs. This keeps each API, worker, or background service easier to manage independently.

### How do I use PM2 with NestJS in production?

On a VPS, PM2 is commonly used to keep your NestJS app running after crashes and across server restarts. You can run pm2 start dist/main.js --name nestjs-app and pm2 save to persist the process list. On Kuberns, the managed deployment workflow reduces the need to configure PM2 yourself.

### What is the NestJS default port and how do I change it for production?

The NestJS default port is 3000, set in main.ts via app.listen(3000). In production you must change this to process.env.PORT so your app binds to the port assigned by the hosting platform. Hardcoding port 3000 is the most common reason NestJS apps are unreachable after deployment.

### How do I use @nestjs/config for environment variables in production?

Install @nestjs/config and import ConfigModule.forRoot() in your AppModule with isGlobal: true. This loads your .env file in development. In production on Kuberns, set variables directly in the dashboard environment section rather than committing a .env file to your repository.

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