Does NestJS Work With Netlify?

Partially CompatibleLast verified: 2026-02-20

NestJS can run on Netlify via serverless functions, but it requires adapters and has cold start limitations that don't suit traditional server architectures.

Quick Facts

Compatibility
partial
Setup Difficulty
Moderate
Official Integration
No — community maintained
Confidence
high
Minimum Versions
NestJS: 9.0.0

How NestJS Works With Netlify

NestJS is built for long-running Node.js servers, while Netlify's serverless functions are stateless, event-driven, and ephemeral. The integration works by adapting NestJS's HTTP handler to work with Netlify's serverless runtime, but this requires significant architectural changes. You'll typically use a community adapter or manually export NestJS as a handler function rather than running it as a traditional server. The cold start problem is real: NestJS's bootstrapping process can take 1-3 seconds on first invocation, making it slower than lighter frameworks. For simple APIs with low traffic, this works acceptably. However, Netlify's edge functions and their compute tiers are better suited for Node.js apps, and you might achieve better results deploying a containerized NestJS app to Netlify's native Node runtime instead of using functions. The developer experience requires careful configuration around request/response mapping, environment variables, and bundling to keep function size reasonable.

Best Use Cases

Migrating existing NestJS microservices to serverless with minimal code changes using adapters
Building middleware-heavy REST APIs that don't require persistent connections
Prototyping enterprise applications where NestJS's structure matters but serverless cost is a factor
Low-traffic internal tools and admin panels where cold starts are acceptable

NestJS on Netlify Functions

bash
npm install @nestjs/core @nestjs/common @nestjs/platform-express
typescript
// netlify/functions/api.ts
import { NestFactory } from '@nestjs/core';
import { ExpressAdapter } from '@nestjs/platform-express';
import express from 'express';
import { AppModule } from '../../src/app.module';

let app: any;

export const handler = async (event: any, context: any) => {
  if (!app) {
    const expressApp = express();
    app = await NestFactory.create(AppModule, new ExpressAdapter(expressApp));
    await app.init();
  }

  return new Promise((resolve) => {
    const expressApp = app.getHttpAdapter().getInstance();
    expressApp(event, context, (err: any, result: any) => {
      if (err) resolve({ statusCode: 500, body: 'Internal error' });
      else resolve(result);
    });
  });
};

Known Issues & Gotchas

warning

NestJS cold starts are slow (1-3s) due to dependency injection initialization, making functions feel unresponsive

Fix: Use Netlify's native Node runtime or compute tier instead of serverless functions for better performance

critical

WebSockets and real-time features don't work in serverless functions due to stateless nature

Fix: Remove real-time features or use Netlify's Blobs API with polling as a workaround

warning

Function size limits (50MB compressed) can be exceeded with large NestJS dependency trees

Fix: Use tree-shaking, ESM build targets, and esbuild with external dependencies marked

info

Environment variable management differs between Netlify's UI and serverless context

Fix: Test environment loading locally with netlify-cli and verify in function logs

Alternatives

  • Express.js + Netlify Functions: Lighter weight, faster cold starts, no DI framework overhead
  • NestJS + Vercel: Better serverless support, faster cold starts, native Node.js runtime
  • NestJS + Railway/Render: Traditional container deployment, no serverless penalties, persistent connections supported

Resources

Related Compatibility Guides

Explore more compatibility guides