Loading lessons...
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)
- Push your project to GitHub.
- Create a new Web Service on Render.
- Connect repository, select Node environment.
- Set Build Command:
npm install. - Set Start Command:
npm start. - 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.PORTso cloud host providers can assign network ports. - Define a valid
"start": "node server.js"script inpackage.json. - Store environment secrets in platform dashboard settings.