Deploy to Vercel Skill
This skill guides you through deploying the To-Do List WebApp to Vercel for both frontend and backend.
Prerequisites
Initial Setup
1. Install Vercel CLI
npm install -g vercel
2. Login to Vercel
vercel login
3. Set Up MongoDB Atlas
- Create a MongoDB Atlas account
- Create a new cluster
- Create a database user
- Whitelist IP addresses (or allow from anywhere: 0.0.0.0/0)
- Get connection string:
mongodb+srv://username:password@cluster.mongodb.net/todolist
Frontend Deployment
1. Configure Frontend Environment
Create frontend/.env.production:
VITE_API_URL=https://your-backend-url.vercel.app/api
2. Build Frontend
cd frontend
npm run build
3. Deploy Frontend
# From frontend directory
vercel
# Or for production
vercel --prod
Follow prompts:
- Set up and deploy: Y
- Which scope: Select your account
- Link to existing project: N (first time)
- Project name: todolist-webapp-frontend
- Directory: ./
- Override settings: N
4. Configure Frontend Environment Variables
In Vercel Dashboard:
- Go to your frontend project
- Settings → Environment Variables
- Add:
VITE_API_URL: Your backend API URL
Backend Deployment
1. Configure Backend Environment
The backend is already configured with vercel.json. Ensure it looks like:
{
"version": 2,
"builds": [
{
"src": "src/index.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "src/index.js"
}
]
}
2. Deploy Backend
# From backend directory
cd backend
vercel
# Or for production
vercel --prod
3. Configure Backend Environment Variables
In Vercel Dashboard:
- Go to your backend project
- Settings → Environment Variables
- Add all variables from
backend/.env.example:
MONGODB_URI: Your MongoDB Atlas connection string
JWT_SECRET: Generate a secure random string
JWT_EXPIRES_IN: 7d
NODE_ENV: production
FRONTEND_URL: Your frontend Vercel URL
PORT: 5000 (optional, Vercel handles this)
4. Redeploy with Environment Variables
After adding environment variables, trigger a new deployment:
cd backend
vercel --prod
Update Frontend with Backend URL
After backend deployment, update frontend environment variable:
- Go to Frontend project in Vercel Dashboard
- Settings → Environment Variables
- Update
VITE_API_URL with your backend URL
- Redeploy frontend:
cd frontend
vercel --prod
Verification
1. Run Pre-Deployment Check
node .agent/skills/deploy-vercel/scripts/pre-deploy-check.js
2. Manual Verification
- Frontend: Visit your frontend URL
- Backend: Visit
https://your-backend-url.vercel.app/api/health
- Test Authentication: Try registering and logging in
- Test Todo Operations: Create, update, delete todos
- Check Logs: View logs in Vercel Dashboard
Continuous Deployment
Set Up GitHub Integration
Push code to GitHub repository
In Vercel Dashboard:
- Import Git Repository
- Select your repository
- Configure:
- Framework: Vite (frontend) / Other (backend)
- Root Directory:
frontend/ or backend/
- Build Command:
npm run build
- Output Directory:
dist (frontend only)
Add environment variables in Vercel
Every push to main branch will trigger automatic deployment
Rollback Deployment
Using Vercel CLI
# List recent deployments
vercel ls
# Promote a specific deployment to production
vercel promote <deployment-url>
Using Vercel Dashboard
- Go to project → Deployments
- Find the desired deployment
- Click "..." → Promote to Production
Environment-Specific Deployments
Preview Deployments
Every branch/PR gets a preview deployment automatically:
# Deploy to preview
vercel
Production Deployments
Only deploy to production when ready:
# Deploy to production
vercel --prod
Monitoring
View Logs
# Real-time logs
vercel logs <deployment-url> --follow
# Recent logs
vercel logs <deployment-url>
Check Build Logs
In Vercel Dashboard:
- Go to project → Deployments
- Click on a deployment
- View build logs and function logs
Troubleshooting
Build Fails
- Check build logs in Vercel Dashboard
- Ensure dependencies are in
dependencies, not devDependencies
- Verify Node.js version matches (set in
package.json engines field)
Environment Variables Not Working
- Ensure variables are set in Vercel Dashboard
- Redeploy after adding variables
- For frontend, variables must start with
VITE_
MongoDB Connection Issues
- Verify connection string is correct
- Check MongoDB Atlas network access (whitelist 0.0.0.0/0)
- Verify database user credentials
- Check MongoDB Atlas cluster status
CORS Errors
Update FRONTEND_URL in backend environment variables:
FRONTEND_URL=https://your-frontend-url.vercel.app
Function Timeout
Vercel has execution time limits:
- Hobby: 10 seconds
- Pro: 60 seconds
Optimize long-running operations or upgrade plan.
Best Practices
- Use Environment Variables: Never commit secrets to git
- Test Before Production: Use preview deployments
- Monitor Performance: Check Vercel Analytics
- Set Up Alerts: Configure Vercel notifications
- Use Custom Domains: Set up custom domain for production
- Enable HTTPS: Vercel provides SSL certificates automatically
- Implement Health Checks: Use
/api/health endpoint
- Review Logs Regularly: Monitor for errors
Custom Domain Setup
- Go to Vercel Dashboard → Project → Settings → Domains
- Add your custom domain
- Configure DNS records as instructed by Vercel
- Update environment variables with new domain
- Redeploy
Cost Optimization
Vercel Free Tier Limits
- 100 GB bandwidth/month
- 100 hours serverless function execution
Optimization Tips
- Use efficient database queries
- Implement caching where possible
- Optimize bundle size (frontend)
- Use preview deployments sparingly
Useful Commands
# Deploy to preview
vercel
# Deploy to production
vercel --prod
# List deployments
vercel ls
# View logs
vercel logs
# Remove deployment
vercel rm <deployment-name>
# Get deployment info
vercel inspect <deployment-url>
# Set environment variable
vercel env add <NAME>
See Also