Node.js Lesson 15: Deployment
Your API works locally — now let’s put it on the internet. This lesson covers deployment to Railway and Render (two free, beginner-friendly platforms).
Prepare Your App for Production
// 1. Make PORT configurable
app.listen(process.env.PORT || 3000);
// 2. Add start script to package.json
"scripts": {
"start": "node app.js",
"dev": "nodemon app.js"
}
// 3. Create .gitignore
node_modules/
.env
// 4. Commit to GitHub
git init
git add .
git commit -m "Initial commit"
git push origin main
Deploy to Railway
# 1. Go to railway.app and sign up
# 2. "New Project" → "Deploy from GitHub Repo"
# 3. Select your repo
# 4. Add environment variables in Railway dashboard:
# PORT=3000 (Railway sets this automatically)
# DB_URL=mongodb+srv://...
# JWT_SECRET=your_secret
# 5. Click Deploy — Railway builds and deploys!
# 6. You get a URL like: myapp.railway.app
Deploy to Render
# 1. Go to render.com
# 2. "New Web Service" → Connect GitHub
# 3. Settings:
# Build command: npm install
# Start command: npm start
# 4. Add environment variables
# 5. Free tier: spins down after 15min inactivity
# (First request is slow — "cold start")
You completed the Node.js course!
What to build next:
- TypeScript + Node.js — Type-safe backends
- WebSockets — Real-time apps with Socket.io
- Docker — Containerize your app
🏋️ Practice Task
Deploy your API from lesson 10 to Railway or Render. Push code to GitHub first. Set environment variables in the dashboard. Test your live API URL with Postman. Share the URL!
💡 Hint: Make sure package.json has “start”: “node app.js” and your port uses process.env.PORT.