Skip to main content
Practice Problems

Deploying Next.js applications

Deployment Options for Next.js

Next.js can be deployed in multiple ways depending on your infrastructure needs: Vercel (managed platform by Next.js creators), Docker containers, Node.js servers, or static export.


The simplest option — built by the Next.js team:

bash
# Install Vercel CLI npm i -g vercel # Deploy vercel

Features:

  • Zero configuration
  • Automatic HTTPS and CDN
  • Edge Functions and Serverless
  • Preview deployments per branch
  • Analytics and monitoring

Docker Deployment

Standalone Output

javascript
// next.config.js const nextConfig = { output: "standalone", };

Dockerfile

dockerfile
# Multi-stage build for minimal image size FROM node:20-alpine AS deps WORKDIR /app COPY package.json package-lock.json ./ RUN npm ci FROM node:20-alpine AS builder WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . RUN npm run build FROM node:20-alpine AS runner WORKDIR /app ENV NODE_ENV=production # Copy only necessary files COPY --from=builder /app/.next/standalone ./ COPY --from=builder /app/.next/static ./.next/static COPY --from=builder /app/public ./public EXPOSE 3000 CMD ["node", "server.js"]
bash
docker build -t my-nextjs-app . docker run -p 3000:3000 my-nextjs-app

Node.js Server

bash
# Build npm run build # Start production server npm start # or node .next/standalone/server.js

Static Export

For fully static sites (no server-side features):

javascript
// next.config.js const nextConfig = { output: "export", };
bash
npm run build # Output in /out directory — deploy to any static host # (Netlify, GitHub Pages, S3, etc.)

Limitations of static export:

  • No Server Components
  • No SSR / ISR
  • No API Routes
  • No Middleware
  • No Image Optimization (without external loader)

Comparison

PlatformBest forFeatures
VercelFull Next.js featuresAll features, zero config
DockerCustom infrastructureFull control, any cloud
Node.jsSimple VPS hostingDirect server control
Static ExportSimple static sitesAny CDN/static host
AWS AmplifyAWS ecosystemGood Next.js support
Cloudflare PagesEdge-firstEdge runtime

Production Checklist

  • Enable reactStrictMode: true
  • Set proper environment variables
  • Configure images.remotePatterns for external images
  • Set up error monitoring (Sentry, etc.)
  • Enable compression (gzip/brotli)
  • Configure caching headers
  • Set up health check endpoint
  • Enable HTTPS

Important:

Vercel provides the best Next.js experience with zero configuration. For self-hosting, use output: "standalone" with Docker for minimal image sizes and full feature support. Use static export only for simple sites that don't need server features. Always test your production build locally before deploying.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.

Finished reading?
Practice Problems