Deployment --- Vercel & Environment Variables
⏱ 15 min read read
Deploy to Vercel --- 3 Steps:
1. Push your project to GitHub
2. Go to vercel.com → New Project → Import from GitHub
3. Click Deploy --- Vercel detects Next.js automatically
# Or use the CLI
npm install -g vercel
vercel # deploys to preview URL
vercel --prod # deploys to production
Environment Variables:
.env.local --- local dev only, never committed to git
.env.development --- only in dev (npm run dev)
.env.production --- only in production build
.env --- all environments (safe defaults only)
NEXT_PUBLIC\_ prefix --- exposed to the browser
No prefix --- server-only (secure)
NEXT_PUBLIC_API_URL=https://api.example.com ← browser-safe
DATABASE_URL=postgres://... ← server-only
AUTH_SECRET=abc123 ← server-only
Accessing Env Vars:
// Server only (Route Handlers, Server Components, Server Actions)
process.env.DATABASE_URL
process.env.AUTH_SECRET
// Client + Server (NEXT_PUBLIC\_ prefix)
process.env.NEXT_PUBLIC_API_URL
Vercel Features:
// Edge Runtime --- deploy to 300+ global PoPs
export const runtime = 'edge'; // in any route or route handler
// Cron jobs --- vercel.json
{ "crons": [{ "path": "/api/cron", "schedule": "0 0 * *
*" }] }
// Preview deployments --- automatic for every PR/branch
Always add .env.local to .gitignore --- it contains secrets.
Set production env vars in Vercel dashboard → Settings → Environment
Variables.
Vercel Edge Functions run at the CDN edge --- ultra-low latency
globally.
Other deployment options: Netlify, Railway, Render, Docker + any
cloud VPS.
1. Push your project to GitHub
2. Go to vercel.com → New Project → Import from GitHub
3. Click Deploy --- Vercel detects Next.js automatically
# Or use the CLI
npm install -g vercel
vercel # deploys to preview URL
vercel --prod # deploys to production
Environment Variables:
.env.local --- local dev only, never committed to git
.env.development --- only in dev (npm run dev)
.env.production --- only in production build
.env --- all environments (safe defaults only)
NEXT_PUBLIC\_ prefix --- exposed to the browser
No prefix --- server-only (secure)
NEXT_PUBLIC_API_URL=https://api.example.com ← browser-safe
DATABASE_URL=postgres://... ← server-only
AUTH_SECRET=abc123 ← server-only
Accessing Env Vars:
// Server only (Route Handlers, Server Components, Server Actions)
process.env.DATABASE_URL
process.env.AUTH_SECRET
// Client + Server (NEXT_PUBLIC\_ prefix)
process.env.NEXT_PUBLIC_API_URL
Vercel Features:
// Edge Runtime --- deploy to 300+ global PoPs
export const runtime = 'edge'; // in any route or route handler
// Cron jobs --- vercel.json
{ "crons": [{ "path": "/api/cron", "schedule": "0 0 * *
*" }] }
// Preview deployments --- automatic for every PR/branch
Always add .env.local to .gitignore --- it contains secrets.
Set production env vars in Vercel dashboard → Settings → Environment
Variables.
Vercel Edge Functions run at the CDN edge --- ultra-low latency
globally.
Other deployment options: Netlify, Railway, Render, Docker + any
cloud VPS.
Log in to track your progress and earn badges as you complete lessons.
Log In to Track Progress