nestjs-deployment

Deploy NestJS applications to production with Docker multi-stage builds and security hardening.

Updated Jun 14, 2026
One-click install
npx skills add https://github.com/ironkid90-s/lucky5-v7 --skill nestjs-deployment-ironkid90-s
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: nestjs-deployment
Source: https://github.com/ironkid90-s/lucky5-v7/tree/main/.ptah/skills/nestjs-deployment
Command: npx skills add https://github.com/ironkid90-s/lucky5-v7 --skill nestjs-deployment-ironkid90-s

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Moving a NestJS application from local development to production involves many failure points: bloated Docker images, webpack bundling errors with native packages, unsafe database migrations, and missing security controls. This Skill provides proven patterns for the entire deployment path. ## Core Features & Use Cases - Multi-Stage Docker Builds: Three-stage Dockerfiles (builder, deps, runtime) that shrink images from 1.2GB to ~200MB with non-root users and health checks. - Webpack Externals Configuration: Fix runtime crashes caused by packages like @prisma/client, bcrypt, or ESM-only SDKs that break when bundled. - Database Migration Strategy: Run prisma migrate deploy on container startup so schema changes apply safely before the app accepts traffic. - Production Hardening: Configure CORS restrictions, rate limiting with @nestjs/throttler, ValidationPipe, environment-driven logging, and memory limits. - Use Case: You have an Nx monorepo NestJS API ready to ship. Use this Skill to generate the production Dockerfile, configure webpack externals for Prisma, and harden main.ts before deploying to DigitalOcean, AWS, or Railway. ## Quick Start Ask the AI to create a production-ready multi-stage Dockerfile and hardened main.ts bootstrap for your NestJS application.

Frequently Asked Questions about nestjs-deployment

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a production Dockerfile for a NestJS app in an Nx monorepo?

Use a three-stage build: a builder stage that installs all dependencies and runs nx build, a deps stage that installs only production dependencies plus webpack externals, and a runtime stage on node:20-alpine with a non-root user, health check, and a CMD that runs prisma migrate deploy before starting node main.js.

Why does my NestJS app crash in Docker with 'Cannot find module' errors?

Packages with native binaries or ESM-only distributions break when webpack bundles them. Mark them as webpack externals using the 'commonjs package-name' format, then explicitly install them in the Docker deps stage since they are excluded from the generated package.json.

How do I run Prisma migrations when deploying NestJS to production?

Run prisma migrate deploy as part of the container startup command, for example CMD ["sh", "-c", "npx prisma migrate deploy && node main.js"]. This applies pending migrations before the app accepts traffic and never use migrate dev in production.

Does this deployment approach work with AWS, GCP, or Railway?

Yes, the same Dockerfile works across DigitalOcean App Platform, AWS ECS/Fargate, Google Cloud Run, and Railway. Build the image, push to a container registry, set environment variables like DATABASE_URL as secrets, and configure the health check path to /api.

How do I prevent Node.js out-of-memory crashes in Docker containers?

Set NODE_OPTIONS with --max-old-space-size to about 85-90% of the container memory limit, such as 450 for a 512MB container. Node.js otherwise sizes its heap against host memory rather than the container limit, causing OOM kills.

What security hardening should a production NestJS app have?

Apply a global ValidationPipe with whitelist and forbidNonWhitelisted, restrict CORS to the frontend URL, add rate limiting with @nestjs/throttler, use helmet for security headers, and limit production log levels to log, error, and warn.