~/techpuraistart learning
~/tutorials/build-a-rest-api/06-deploying-for-free
beginner·part 6 of 6·1 min read

Deploying for free

Updated Aug 6, 2026Node.js · Deployment

Six parts in, you have a real API with routes, error handling, a database, and auth. This last part gets it off your machine and onto a public URL, for free.

Picking a host

Vercel's free tier works well for this API since Express apps run there as serverless functions with no extra configuration beyond an entry file. A managed Postgres add-on (or a free instance from a host like Neon or Supabase) covers the database from part four.

Preparing the entry point

Serverless platforms expect your app to export a request handler instead of calling app.listen() directly. Split that out:

js
// api/index.js
const app = require('../app');
module.exports = app;
js
// app.js
const express = require('express');
const app = express();

// ...all your routes and middleware from parts 1–5

module.exports = app;

Locally, keep a small server.js that calls app.listen() for development — it's never deployed.

Setting environment variables

DATABASE_URL and JWT_SECRET need to exist in production the same way they did in your local .env file. Set them in your hosting provider's dashboard rather than committing them — this is the one step people skip and then spend an hour debugging.

Checkpoint

After deploying, call your live health check route from part two first: GET https://your-app.vercel.app/api/health. If that responds, your routing and environment are wired correctly before you debug anything database-related.

What's next

You've now built and shipped a complete API: routing, error handling, a real database, authentication, and a live deployment. The same shape — routes, middleware, error handling, deploy — is what you'll reach for on every backend project after this one.

← previous5. Auth middleware