# The Cheapest Way to Host a Node.js API That Never Sleeps

URL: https://www.savemores.store/vps/cheapest-nodejs-api-hosting
Author: Mr. Ahmed · Published 2026-09-05 · Updated 2026-09-05 · VPS & deployment

## Short answer

- For an API that must stay awake, the realistic floor is about $5–7 a month: Render Starter, Railway Hobby, Fly.io or an entry VPS.
- Render's free web service costs $0 but sleeps when idle, and waking it takes seconds; Fly.io has no free tier for new accounts, and Railway has no permanent one.
- Platforms bill per service (an API, a worker and staging at ~$7 each is ~$21/month); a VPS bills per machine, so the second and third services cost nothing.
- On a VPS, Caddy reverse-proxies the API with automatic Let's Encrypt HTTPS in a three-line config, with no Certbot or cron job.
- For exactly one API, a PaaS is cheaper once you value your own time; for three or more services, a VPS wins.

## First decide whether the API is allowed to sleep

'Cheapest' turns on one question. Free tiers stay free by suspending your process when traffic stops, and waking it takes several seconds. For a hobby dashboard you open twice a week, that is acceptable. For anything a user is waiting on, a multi-second cold start is worse than no API.

Rule out sleeping and the options narrow fast, with prices clustering around $5–7 a month. What differs is what that money buys.

## What the options cost (September 2026)

Free tiers have shrunk. Fly.io no longer gives new accounts a free tier and requires a card. Railway has no permanent free tier. Render still offers a genuinely free web service, with the cold-start caveat.

| Option | Realistic monthly cost | What you get |
| --- | --- | --- |
| Render free | $0 | 512 MB, no card needed, sleeps when idle. Cold starts take seconds. |
| Render Starter | ~$7 per service | Always-on 512 MB, managed deploys from Git, no server admin. |
| Railway Hobby | ~$5–7 for a small always-on API | Usage-based; widely regarded as the best developer experience of the three platforms. |
| Fly.io | ~$5–12 | Card required, no free tier for new users. Worth it specifically for multi-region or edge deployment. |
| Entry VPS (e.g. KVM 1) | $4.99/mo on a 48-month term | 1 vCPU, 4 GB RAM, 50 GB NVMe, root access, and it hosts your other projects at no extra cost. |

## Billing model beats sticker price

This is what decides it for most people. Managed platforms charge per service. The API is one. Add a background worker and it is two. Add staging and it is three. At about $7 each, that is $21 a month and rising.

A VPS charges per machine. The second API on the box is free, and so are the third, the cron worker, Postgres and the staging copy. A 4 GB server takes a surprising number of small Node processes before it complains.

The honest answer, then: for exactly one API, a PaaS is cheaper once you price your own time. For three or more things, a VPS is cheaper and the gap keeps widening.

> From the bench: What the VPS invoice leaves out is your attention: OS updates, TLS, firewall rules, backups, and being the one who gets the alert. If that is worth more than about $15 a month to you, pay the platform and close this tab. The boring choice is usually right.

## VPS setup: PM2 plus Caddy

When all you need is a reverse proxy with HTTPS, Caddy does in three lines what Nginx plus Certbot takes about forty to do. It fetches and renews Let's Encrypt certificates on its own, with no cron job and no extra tool. For a small API it is the right default.

Use Node 24 LTS (Active LTS as of September 2026) and PM2 to keep the process running. Before you start, point the API hostname at the server ([DNS guide](https://www.savemores.store/vps/point-domain-dns)), because Caddy requests the certificate the moment it loads the config.

1. Install Node 24 and PM2, then start the API.
2. Bind the API to 127.0.0.1 so only the proxy can reach it.
3. Install Caddy from its official apt repository.
4. Write the Caddyfile and reload Caddy. HTTPS is issued automatically.

1. Node, PM2 and the API:

```bash
curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash -
sudo apt-get install -y nodejs

sudo npm install -g pm2

cd /var/www/api
npm ci --omit=dev
pm2 start server.js --name api
pm2 save
pm2 startup systemd
# run the sudo command PM2 prints, then 'pm2 save' again
```

2. Listen on loopback only:

```js
const PORT = process.env.PORT || 5000;

app.listen(PORT, "127.0.0.1", () => {
  console.log("API on 127.0.0.1:" + PORT);
});
```

3. Install Caddy:

```bash
sudo apt-get install -y debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' \
  | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' \
  | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt-get update && sudo apt-get install -y caddy
```

4. /etc/caddy/Caddyfile, the entire config:

```caddyfile
api.example.com {
    reverse_proxy 127.0.0.1:5000
}
```

```bash
sudo systemctl reload caddy
```

## Verify it worked

Test the API directly first, then through Caddy. That tells you immediately which side is broken.

- **Certificate not issued**: the A record has not propagated, or ports 80 and 443 are closed. If UFW is on, `sudo ufw allow 80/tcp` and `sudo ufw allow 443/tcp`.
- **502 from Caddy**: the API is not running, or it is on a different port than the one in `reverse_proxy`. Check `pm2 logs api`.
- **Works locally, times out publicly**: check that the hostname in the Caddyfile matches the DNS record exactly.

```bash
pm2 status                            # api should be 'online'
curl -I http://127.0.0.1:5000          # the API answers locally
curl -I https://api.example.com        # through Caddy, with a valid certificate
sudo systemctl status caddy
journalctl -u caddy --no-pager -n 50   # certificate errors show up here
```

## A second API is one more block

This is the VPS argument in config form. Another PM2 process on another port, three more lines in the Caddyfile, another certificate issued without you asking. The bill does not change. For more on stacking projects, see [multiple sites on one VPS](https://www.savemores.store/vps/multiple-sites-one-vps).

```bash
cd /var/www/api-two
PORT=5001 pm2 start server.js --name api-two
pm2 save
```

```caddyfile
api.example.com {
    reverse_proxy 127.0.0.1:5000
}

api2.example.com {
    reverse_proxy 127.0.0.1:5001
}
```

## Costs that arrive in month three

The launch price is rarely the final price. These are the line items that appear later.

- **Bandwidth.** Most VPS plans include several terabytes; managed platforms are often tighter and bill overage. If the API serves files or images, check this first.
- **Backups.** Included weekly on many VPS plans; a 20–30% surcharge at some cloud providers.
- **The database.** A free Atlas or Postgres tier is fine until it is not, and managed database pricing often exceeds the compute it serves.
- **Cold starts.** They cost user patience rather than dollars, which makes them easy to under-price until someone complains.
- **Renewal rates.** Promotional VPS prices roughly double at renewal. Budget for the real number; the [renewal price guide](https://www.savemores.store/guides/hostinger-renewal-price) has the detail.

## One line per situation

If you want the answer without the reasoning:

- One API, occasional traffic, no appetite for ops: Render's free tier, and accept the cold starts.
- One API that must stay awake, and you do not want a server: Render Starter or Railway, around $7.
- Two or more services, or a database on the same box: an entry VPS, where each addition costs nothing.
- Multi-region or edge latency requirements: Fly.io. This is the case where it clearly beats the rest.

## If the VPS route fits

An entry KVM plan with 4 GB of RAM runs a Node API, a database and several other small projects at once, and that is what makes per-machine pricing pay off. The links here apply coupon **WEBHOST2026** automatically, and longer terms carry the lower monthly rate. Plan details are on the [KVM 1 deal page](https://www.savemores.store/hostinger-deals/kvm-1).

## FAQ

### What is the cheapest way to host a Node.js API?

Render's free tier costs nothing if cold starts are acceptable. For an always-on API, expect about $5 to $7 a month on Render Starter, Railway or an entry VPS, and the VPS becomes the cheapest once you run two or more services.

### Does Fly.io still have a free tier?

Not for new accounts. Fly.io requires a card and no longer offers a free tier to new users.

### Is Caddy or Nginx better for a Node API?

Caddy is simpler for a small API because it obtains and renews HTTPS certificates automatically from a three-line config. Nginx is more flexible but needs Certbot and more configuration.

### How many Node APIs can one 4 GB VPS run?

Several small ones. Each extra API is another PM2 process on its own port and another Caddy block, and the monthly price does not change.
