Back to materials

Deployment guide

Table of Contents

1. Overview

Deployment makes your code accessible on the internet via a URL.

Key terms

TermMeaning
BuildConverting code into optimized files for production
CDNServers worldwide that serve your site fast
ProductionThe live version users see
PreviewA test version to check before going live
Environment variablesSecret configuration values (API keys, database URLs)

2. Prerequisites

  1. Complete Setup fundamentals
  2. Install Node.js:
    • macOS: brew install node
    • Windows: scoop install node
  3. Create a Vercel account (sign up with GitHub)

3. Vercel deployment

Vercel is a deployment platform optimized for frontend frameworks and static sites. It connects to your Git repository and automatically deploys your code whenever you push changes.

Why Vercel?

  • Zero configuration for most frameworks
  • Automatic HTTPS
  • Global CDN (fast everywhere)
  • Free tier: 100 GB bandwidth/month
  • Every PR gets its own preview URL

Connect repository

  1. Go to vercel.com, click "Add New..." then "Project"
  2. Select your GitHub repository
  3. Vercel auto-detects your framework
  4. Click "Deploy"

You get a URL like: https://your-project.vercel.app

Automatic deployments

ActionResult
Push to mainProduction deployment (live site updates)
Push to other branchPreview deployment (unique test URL)
Open Pull RequestPreview URL added as comment

Docs: Vercel

4. Environment variables

Environment variables are configuration values stored outside your code. They hold sensitive data like API keys, database URLs, and secrets. Never commit them to Git.

Via dashboard

  1. Go to Project > Settings > Environment Variables
  2. Add name + value
  3. Select environment (Production, Preview, Development)

Via CLI

npm i -g vercel          # Install CLI
vercel login             # Authenticate
vercel env add KEY_NAME  # Add variable (prompts for value)
vercel env pull          # Pull vars to local .env

Environment scopes

ScopeWhen it's used
ProductionLive deployments on your main domain
PreviewPR and branch preview deployments
DevelopmentWhen running vercel dev locally

Next.js note: Client-side variables must be prefixed with NEXT_PUBLIC_

NEXT_PUBLIC_API_URL=https://api.example.com  # Accessible in browser
DATABASE_URL=postgres://...                   # Server-side only

Docs: Vercel CLI

5. Other platforms

Other platforms serve different needs:

PlatformBest forFree tierDeploy command
VercelNext.js, React100 GB bandwidthvercel --prod
NetlifyStatic sites, forms300 credits/monetlify deploy --prod
RailwayFull-stack + database$5 credit/morailway up
RenderHeroku replacement750 hours/moGit push or render.yaml
ReplitBrowser-based dev10 GiB egressClick "Deploy"

Quick recommendations:

SituationUse
First deployment / learningVercel or Replit
Next.js appVercel
Need a databaseRailway or Render
No local setupReplit

6. Security basics

Deployed applications are publicly accessible. The most common mistake is exposing API keys, database credentials, or other secrets in your code.

Always add to .gitignore:

.env
.env.local
.env.production
.env*.local
.vercel
node_modules

Checklist before production:

  • All secrets in platform's dashboard (not in code)
  • .env files in .gitignore
  • No hardcoded API keys in source
  • HTTPS enabled (automatic on Vercel/Netlify)

7. Troubleshooting

ProblemSolution
Module not foundRun npm install package-name, commit package.json
Works locally, fails deployedCheck env vars are set in Vercel dashboard
404 on page refresh (React/Vite)Add vercel.json with rewrites (see below)
Node version mismatchAdd "engines": { "node": "22.x" } to package.json
Build failsCheck logs in Vercel dashboard under deployment > "Logs"

Fix for React/Vite 404s:

{
  "rewrites": [{ "source": "/(.*)", "destination": "/" }]
}

8. Reference

Platforms

Documentation

Commands

CommandDescription
npm i -g vercelInstall Vercel CLI
vercel loginAuthenticate
vercelDeploy to preview
vercel --prodDeploy to production
vercel env pullPull env vars to local
vercel env add NAMEAdd env variable
vercel devRun local dev server