Follow this guide to deploy your project to production. We will use Vercel for the Frontend and Railway (or Render) for the Backend.
Vercel is the best home for React/Vite projects.
- Create a free account on vercel.com.
- Install the Vercel CLI (optional) or connect your GitHub repository directly.
- Project Settings:
- Framework Preset: Vite
- Build Command:
npm run build - Output Directory:
dist - Root Directory:
client
- Environment Variables:
- Add
VITE_API_URLand set it to your deployed Backend URL (e.g.,https://api.codecraftkids.com).
- Add
- Click Deploy!
Railway is fast and reliable but requires a trial credit to start.
- Connect your GitHub on railway.app.
- Select the
Serverfolder as the root. - Environment Variables:
MONGODB_URI(Use your MongoDB Atlas link)JWT_SECRET(Your secure key)PORT=5000
- Railway will automatically detect
node server.jsand deploy.
Render offers a "Free Tier" for Web Services.
- Create an account on render.com.
- Select New > Web Service and connect your repo.
- Root Directory:
Server - Build Command:
npm install - Start Command:
node server.js - Environment Variables: (Same as Railway). Note: Render free tier "sleeps" after 15 minutes of inactivity. The first request after a long time might take 30-60 seconds to wake up.
If you get a CORS error, ensure your backend allows the Vercel URL. Update Server/server.js:
app.use(cors({
origin: ["http://localhost:5173", "https://your-vercel-domain.com"],
credentials: true
}));For production, you must use a cloud database like MongoDB Atlas. Do not use local mongodb://localhost in your production environment variables.
Happy Deploying! 🚀