Lesson 37 +10 XP

Deployment to Vercel & Render

Deploying Node & Express APIs

Modern cloud platforms allow deploying Express APIs easily from Git repositories.

1. Preparing Express App for Cloud Deployment

Ensure your package.json specifies a start script and binds to process.env.PORT:

{
  "name": "express-api",
  "version": "1.0.0",
  "scripts": {
    "start": "node server.js",
    "dev": "nodemon server.js"
  },
  "engines": {
    "node": ">=18.0.0"
  }
}

2. Deploying to Render (Web Service)

  1. Push your project to GitHub.
  2. Create a new Web Service on Render.
  3. Connect repository, select Node environment.
  4. Set Build Command: npm install.
  5. Set Start Command: npm start.
  6. Add Environment Variables (MONGODB_URL, JWT_SECRET) in dashboard.

3. Deploying to Vercel (Serverless Functions)

Create a vercel.json configuration file in project root:

{
  "version": 2,
  "builds": [
    {
      "src": "server.js",
      "use": "@vercel/node"
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "server.js"
    }
  ]
}

TL;DR

  • Always configure process.env.PORT so cloud host providers can assign network ports.
  • Define a valid "start": "node server.js" script in package.json.
  • Store environment secrets in platform dashboard settings.