📖 Notes
LESSON 31 OF 32
Deploy to Railway
Hosting a Live Server + Database
Your Express backend needs a host that keeps a process running continuously — Railway does that, and MongoDB Atlas gives you a free hosted database to connect it to.
Backend + Database Hosting
Step by Step
1
Create a free MongoDB Atlas cluster
Get a connection string (URI) with your username, password, and cluster address.
2
Whitelist network access
Allow connections from anywhere (0.0.0.0/0) so Railway's servers can reach it.
3
Push your Express project to GitHub
Same repo pattern as Lesson 29.
4
Import the repo on railway.app
Railway detects Node.js automatically and runs
npm install && npm start.5
Set environment variables
MONGO_URI and JWT_SECRET — never commit these to Git.6
Connect frontend to backend
Update the Vercel frontend's API URL env variable to point at your live Railway URL.
⚠️
CORS will block you by default
Your Vercel frontend and Railway backend live on different domains — the backend must explicitly allow the frontend's origin using the
cors Express middleware, or every fetch call will fail silently in the browser console.