Deployment
Next.js deployment Vercel, Docker aur apne server par, output standalone, next start aur production checklist, Roman Urdu mein step by step samjhein.
On this page
1. Deployment kya hai?
Next.js ke chaar bare raste hain:
| Option | Feature support |
|---|---|
| Vercel (verified adapter) | Saare features, zero config |
Node.js server (next start) | Saare features |
| Docker container | Saare features |
Static export (output: "export") | Limited, server wale features nahi |
2. Kyun zaroori hai?
next dev sirf development ke liye hai: slow, unoptimized aur debugging tools ke saath. Production mein optimized build, caching aur sahi environment variables chahiye.
| next dev | Production deployment |
|---|---|
| Har request par on demand compile | Pehle se optimized build |
| Unminified code aur dev warnings | Minified, code split bundles |
| Local machine par chalta hai | Server ya platform par 24/7 |
| Local env files | Platform ke secure environment variables |
| Ek user, aap khud | Hazaron users, scaling aur caching |
3. Kahan use hota hai?
| Situation | Behtar choice |
|---|---|
| Personal project, startup, fast launch | Vercel |
| Apna VPS (Hostinger, DigitalOcean) | next build + next start, PM2 ya systemd ke saath |
| Kubernetes, Cloud Run, Fly.io | Docker + output: "standalone" |
| Sirf static marketing site | output: "export", kisi bhi static host par |
4. Kaise kaam karta hai?
Vercel par yeh sab khud hota hai: GitHub repo connect karein, har push par preview deployment aur main branch par production deployment banta hai.
5. Code example
Self-hosting: Node.js server
{
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
}
}npm ci
npm run build
PORT=3000 npm run startDocker ke liye standalone output
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
output: "standalone",
};
export default nextConfig;FROM node:22-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM node:22-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
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"]Upar wala Dockerfile hai. Build aur run:
docker build -t znpedia .
docker run -p 3000:3000 --env-file .env.production znpediaVercel CLI se deploy
npm i -g vercel
vercel
vercel --prodCode kaise kaam kar raha hai?
| Cheez | Matlab |
|---|---|
next build | Production build .next folder mein |
next start | Production server, default port 3000 |
output: "standalone" | .next/standalone mein sirf zaroori files aur server.js |
.next/static aur public copy | Standalone inhein khud copy nahi karta, Dockerfile mein karna padta hai |
| Multi-stage build | Builder ki bhaari dependencies final image mein nahi aati |
--env-file | Secrets image mein bake nahi hote, runtime par aate hain |
vercel --prod | Production deployment, bina flag ke preview |
6. Common mistakes
Galati: Production server par next dev chalana
Why? Dev mode slow hai, har request par compile karta hai aur production optimizations band hoti hain.
Behtar: Server par hamesha next build ke baad next start chalao.
Galati: Standalone output mein static aur public copy na karna
Why? Page khulta hai lekin CSS, JS chunks aur images 404 dete hain.
Behtar: Dockerfile mein .next/static aur public folders standalone ke saath copy karo, ya unhein CDN se serve karo.
Galati: NEXT_PUBLIC variables runtime par badalne ki koshish
Why? NEXT_PUBLIC_ wali values build ke waqt client bundle mein likh di jati hain, baad mein badalne se asar nahi hota.
Behtar: Public values build se pehle set karo, aur jo values runtime par chahiye unhein server par process.env se parho.
Galati: Secrets Docker image mein COPY kar dena
Why? Image share ya push hote hi .env ke secrets bhi leak ho jate hain.
Behtar: Secrets .dockerignore mein rakho aur runtime par env vars ya platform secrets se do.
Interview tip
"output: "standalone" kya karta hai?" Build ke dauran Next.js trace karta hai ke runtime par kaun si files aur node_modules packages chahiye, aur sirf woh .next/standalone mein ek server.js ke saath rakhta hai. Is se Docker image bohot chhoti ban jati hai.
7. Pehle aur baad mein kya seekhein?
| Stage | Chapters |
|---|---|
| Pehle | Environment Variables, next.config & Turbopack, Testing Next.js Apps |
| Saath mein | Performance & Core Web Vitals, Sitemap, Robots & OG Images |
| Baad mein | Database Integration, Authentication |
Final quick revision
| Point | Detail |
|---|---|
| Sab se aasaan | Vercel, Git connect aur deploy |
| Apna server | next build phir next start |
| Docker | output: "standalone" aur node server.js |
| Standalone ke saath copy | .next/static aur public |
| Static site | output: "export", limited features |