Deployment guide
Table of Contents
- 1. Overview
- 2. Prerequisites
- 3. Vercel deployment
- 4. Environment variables
- 5. Other platforms
- 6. Security basics
- 7. Troubleshooting
- 8. Reference
1. Overview
Deployment makes your code accessible on the internet via a URL.
Key terms
| Term | Meaning |
|---|---|
| Build | Converting code into optimized files for production |
| CDN | Servers worldwide that serve your site fast |
| Production | The live version users see |
| Preview | A test version to check before going live |
| Environment variables | Secret configuration values (API keys, database URLs) |
2. Prerequisites
- Complete Setup fundamentals
- Install Node.js:
- macOS:
brew install node - Windows:
scoop install node
- macOS:
- 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
- Go to vercel.com, click "Add New..." then "Project"
- Select your GitHub repository
- Vercel auto-detects your framework
- Click "Deploy"
You get a URL like: https://your-project.vercel.app
Automatic deployments
| Action | Result |
|---|---|
Push to main | Production deployment (live site updates) |
| Push to other branch | Preview deployment (unique test URL) |
| Open Pull Request | Preview 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
- Go to Project > Settings > Environment Variables
- Add name + value
- 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
| Scope | When it's used |
|---|---|
| Production | Live deployments on your main domain |
| Preview | PR and branch preview deployments |
| Development | When 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:
| Platform | Best for | Free tier | Deploy command |
|---|---|---|---|
| Vercel | Next.js, React | 100 GB bandwidth | vercel --prod |
| Netlify | Static sites, forms | 300 credits/mo | netlify deploy --prod |
| Railway | Full-stack + database | $5 credit/mo | railway up |
| Render | Heroku replacement | 750 hours/mo | Git push or render.yaml |
| Replit | Browser-based dev | 10 GiB egress | Click "Deploy" |
Quick recommendations:
| Situation | Use |
|---|---|
| First deployment / learning | Vercel or Replit |
| Next.js app | Vercel |
| Need a database | Railway or Render |
| No local setup | Replit |
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)
-
.envfiles in.gitignore - No hardcoded API keys in source
- HTTPS enabled (automatic on Vercel/Netlify)
7. Troubleshooting
| Problem | Solution |
|---|---|
Module not found | Run npm install package-name, commit package.json |
| Works locally, fails deployed | Check env vars are set in Vercel dashboard |
| 404 on page refresh (React/Vite) | Add vercel.json with rewrites (see below) |
| Node version mismatch | Add "engines": { "node": "22.x" } to package.json |
| Build fails | Check logs in Vercel dashboard under deployment > "Logs" |
Fix for React/Vite 404s:
{
"rewrites": [{ "source": "/(.*)", "destination": "/" }]
}
8. Reference
Platforms
- Vercel - Frontend deployment platform
- Netlify - Static site hosting
- Railway - Full-stack deployment with databases
- Render - Application hosting
- Replit - Browser-based development and deployment
Documentation
- Vercel Docs - Platform documentation
- Vercel CLI - Command-line deployment tool
- Next.js Deployment - Framework-specific guides
- Netlify Docs - Platform documentation
- Railway Docs - Platform documentation
- Render Docs - Platform documentation
- Node.js - JavaScript runtime
Commands
| Command | Description |
|---|---|
npm i -g vercel | Install Vercel CLI |
vercel login | Authenticate |
vercel | Deploy to preview |
vercel --prod | Deploy to production |
vercel env pull | Pull env vars to local |
vercel env add NAME | Add env variable |
vercel dev | Run local dev server |