AiTechWorlds
AiTechWorlds
Deploying a web application used to require configuring servers, managing infrastructure, and dealing with SSL certificates. Modern platforms like Vercel and Netlify remove all of that — push your code to GitHub and your app is live in under a minute, with global CDN, HTTPS, automatic deployments, and preview URLs for every pull request.
Vercel is made by the creators of Next.js. It understands every Next.js feature out of the box and needs zero configuration.
Push your project to GitHub
Go to vercel.com and click "Add New Project"
Import your GitHub repository — Vercel auto-detects Next.js and configures the build
Your app is live at your-app-name.vercel.app. Done.
npm run build on every pushcache: "no-store" run as serverless functionsnext/image optimization via Vercel's image serviceNever hardcode secrets. Set them in the Vercel dashboard:
DATABASE_URL, JWT_SECRET, STRIPE_SECRET_KEY, etc.For local development, create .env.local:
DATABASE_URL=postgresql://localhost:5432/myapp_dev
JWT_SECRET=local-dev-secret-change-this
NEXT_PUBLIC_API_URL=http://localhost:3000
Variables prefixed with NEXT_PUBLIC_ are exposed to the browser. All others stay server-side only.
To pull Vercel's environment variables locally:
npm install -g vercel
vercel login
vercel link # link your local folder to the Vercel project
vercel env pull # download env vars to .env.local
myapp.com)npm install -g vercel
# Deploy to preview
vercel
# Deploy to production
vercel --prod
# View logs
vercel logs
# List deployments
vercel ls
Netlify is excellent for static sites, React SPAs without SSR, and projects built with Vite:
npm run builddistEither connect your GitHub repo through the Netlify UI, or use the CLI:
npm install -g netlify-cli
netlify login
netlify init
netlify deploy --prod
# netlify.toml — in the root of your project
[build]
command = "npm run build"
publish = "dist"
# Redirect all routes to index.html for SPAs
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
# Security headers
[[headers]]
for = "/*"
[headers.values]
X-Frame-Options = "DENY"
X-Content-Type-Options = "nosniff"
Referrer-Policy = "strict-origin-when-cross-origin"
The redirect rule is essential for single-page apps — without it, refreshing /dashboard returns a 404 because there's no dashboard.html file.
Serverless functions in a netlify/functions/ folder:
// netlify/functions/send-email.ts
import type { Handler } from "@netlify/functions";
export const handler: Handler = async (event) => {
if (event.httpMethod !== "POST") {
return { statusCode: 405, body: "Method not allowed" };
}
const { email, name } = JSON.parse(event.body ?? "{}");
// Send email logic here...
return {
statusCode: 200,
body: JSON.stringify({ success: true }),
};
};
Callable at /.netlify/functions/send-email.
Before every production deployment:
✅ Environment variables set on the platform
✅ Build passes locally (npm run build)
✅ No console.log with sensitive data
✅ API keys are in env vars, not hardcoded
✅ .env is in .gitignore
✅ Database connection string uses production database
✅ CORS configured for your production domain
✅ Error pages return appropriate HTTP status codes
✅ Images optimized (use next/image or compress manually)
✅ Remove console.log statements used during development
Both Vercel and Netlify create a unique URL for every pull request. The URL format is typically:
https://my-app-git-feature-branch-username.vercel.app
This means:
Always test your preview deployment before merging. Many bugs only appear in the deployed environment.
Local databases don't follow you to production. Use managed databases:
PostgreSQL options:
After creating a production database, copy the connection string into your environment variables on Vercel/Netlify.
Run migrations on deployment:
// package.json
{
"scripts": {
"build": "prisma generate && prisma migrate deploy && next build"
}
}
prisma migrate deploy applies any pending migrations. Running it as part of the build ensures your schema is always in sync with your code.
Know when things break:
# Vercel — view real-time logs
vercel logs --follow
# Check function execution in Vercel dashboard
# Project → Functions → click any function → view invocations and logs
Consider adding error monitoring with Sentry:
npm install @sentry/nextjs
npx @sentry/wizard@latest -i nextjs
Sentry captures unhandled errors and sends you an alert when something goes wrong in production — before your users report it.
Next lesson: Environment variables and secrets — managing configuration safely across environments.
Get this course's notes on Telegram!
Free cheat sheets, summaries & practice exercises