Script Valley
Express.js: APIs and Middleware
Testing and Deploying Express APIsLesson 6.4

How to deploy an Express API to Railway or Render

Railway deployment, Render deployment, start script in package.json, PORT from env, Procfile optional, environment variables in dashboard, zero-downtime deploy, health check endpoint

Deploying Express to Railway or Render

Railway and Render are the fastest ways to deploy Node.js apps — connect your GitHub repo, set environment variables, and they handle the rest.

Required changes before deploying

// package.json
{
  "scripts": {
    "start": "node src/server.js",
    "dev": "nodemon src/server.js"
  },
  "engines": {
    "node": ">=18.0.0"
  }
}

server.js — use PORT from env

const app = require('./app');
const PORT = process.env.PORT || 3000;

app.listen(PORT, () => {
  console.log(`Server running on port ${PORT}`);
});

Health check endpoint — required by most platforms

app.get('/health', (req, res) => {
  res.json({ status: 'healthy', uptime: process.uptime() });
});

Railway: New Project → Deploy from GitHub → Add environment variables in the Variables tab. It auto-detects Node.js and runs your start script.

Render: New Web Service → Connect repo → Set Build Command (npm install) and Start Command (npm start) → Add env vars in Environment tab.

Never hardcode PORT — platforms inject it automatically and it changes between deployments.

Up next

How to document an Express API with Swagger/OpenAPI

Sign in to track progress