Master Code
On The Go

Learn. Practice. Build.

Home › How-To › Deploy Node.js Free

Node.js Guide

How to Deploy a Node.js App for Free

Get your Node.js API or app onto the internet in under 20 minutes. Compare three free hosts and deploy step by step.

Quick answer: Use Render for the simplest deploy, Railway for a $5/month credit on any resource, or Fly.io for global distribution. All three auto-deploy from GitHub.

⚡ Host Comparison

HostFree TierSleeps?Best For
Render750 hrs/mo web serviceYes (15 min idle)Simple deploys, beginners
Railway$5 credit/moNoAPIs + databases together
Fly.io3 shared VMs + 160GBNoGlobal apps, more control
VercelServerless functionsN/ANext.js, static + API routes
1

Prepare Your Project

Before deploying, make sure your package.json has:

{
    "name": "my-api",
    "version": "1.0.0",
    "type": "module",
    "scripts": {
        "start": "node server.js",
        "dev": "nodemon server.js"
    },
    "engines": {
        "node": ">=20.0.0"
    }
}
  • start script — the host runs this to start your app
  • engines.node — tells the host which Node version to use
  • PORT env variable — use process.env.PORT, not hardcoded
2

Use process.env.PORT

Every host assigns a port. Your app must listen on it:

const PORT = process.env.PORT || 3000;

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

Common bug: Hardcoding app.listen(3000) causes deploy failures. Always read from process.env.PORT.

3

Push to GitHub

git init
git add .
git commit -m "Ready to deploy"
git branch -M main
git remote add origin https://github.com/USERNAME/REPO.git
git push -u origin main

Make sure .env and node_modules are in .gitignore.

4

Deploy on Render (Recommended)

  1. Go to render.com and sign up with GitHub
  2. Click New → Web Service
  3. Connect your GitHub repo
  4. Render auto-detects Node.js — keep default settings
  5. Add environment variables (see Step 5)
  6. Click Deploy Web Service

First deploy takes 2–5 minutes. Subsequent deploys are faster.

5

Add Environment Variables

In your host's dashboard, add every variable from your .env:

DATABASE_URL=postgres://...
JWT_SECRET=your-production-secret
NODE_ENV=production
OPENAI_API_KEY=sk-...

💡 Tip: Use different JWT secrets and API keys for dev and production. Never reuse credentials between environments.

6

Add a Database (Render / Railway)

Both Render and Railway offer free PostgreSQL:

  1. Render: New → PostgreSQL → Free tier
  2. Copy the Internal Database URL
  3. Add it as DATABASE_URL to your web service
  4. Redeploy — your app connects automatically

The internal URL only works from services inside the same host — never expose the external URL publicly.

7

Deploy Updates

Push to your main branch:

git add .
git commit -m "Fix bug"
git push

The host auto-deploys within 1–2 minutes. Pull requests get preview URLs on Render and Railway.

🎯 Production Checklist

❓ Frequently Asked Questions

Best free host for Node.js?;

Render for simplicity, Railway for APIs + databases together, Fly.io for global distribution.

Do free hosts sleep?

Render sleeps after 15 minutes on the free tier (30–60s cold start). Railway and Fly.io don't sleep on free tiers.

Can I deploy a database with my app?

Yes. Render and Railway both offer free PostgreSQL. Connect via DATABASE_URL.

How do I deploy updates?

Push to main on GitHub. Auto-deploy triggers automatically.

Is the free tier enough for real apps?

For personal projects, yes. For production with real users, you'll want a paid plan after you outgrow the limits.

🎯 What's Next?

← All How-To Guides