An API running all month, never called — still paying for the server
Imagine you write a small API for your team’s internal tool: receive webhooks, process data, return JSON. Nothing complex, just a few endpoints. But to deploy it, you need a server running 24/7, with Node.js installed, Nginx configured, SSL handled, security updates managed… And at the end of the month, you’re still paying for the VPS even though actual traffic was only a few hundred requests.
I did exactly that for nearly 3 years. A $5/month VPS running an Express app with fewer than 10,000 total requests per month. Efficient? No. Is there a better way? Yes.
The Core Problem: Express + VPS Isn’t Always the Right Tool
Express.js was born in the era when servers were still physical machines. The single Node.js process handling all requests still makes sense for large web apps — when you need a database connection pool, session management, and a full middleware stack. For those use cases, Express does the job well.
But for small APIs — webhook handlers, simple proxies, auth services, rate limiters — the “always-running server” model creates several real-world problems:
- Idle cost adds up: A server doing nothing still consumes RAM, CPU, and money.
- Manual scaling: A traffic spike means you have to manually spin up instances and configure a load balancer.
- Fixed geography: Server in Singapore but users in the US — higher latency than necessary.
- Operational overhead: OS updates, monitoring for process crashes, backups — all your responsibility.
The Alternatives: Lambda, Vercel Functions, or Cloudflare Workers?
The simplest solution: only pay when your code actually runs. Serverless functions do exactly that — but each platform handles things differently, and the trade-offs vary:
- AWS Lambda: Powerful and flexible, but cold starts can reach 1–2 seconds with Node.js. Configuring IAM, VPC, and API Gateway is far more complex than most use cases actually need.
- Vercel/Netlify Functions: Simpler, with great frontend integration. But execution time is limited (10 seconds on the free plan), and requests still route to a fixed region.
- Cloudflare Workers: Runs on V8 isolates instead of a Node.js process. Cold starts under 5ms. Deployed across 300+ PoPs globally. Free plan: 100,000 requests/day.
What sets Cloudflare Workers apart from the other two: it doesn’t use the Node.js runtime — it uses V8 isolates, the same engine as Chrome, but starts in a few milliseconds instead of hundreds of ms. The trade-off is that you don’t have the full Node.js API (fs, net aren’t available), but for typical Web APIs that rarely matters.
Hono: The Lightest Framework for Modern Web APIs
Hono (Japanese: 炎 — flame) is a web framework designed from the ground up for edge runtimes: Cloudflare Workers, Deno, Bun, and even Node.js. The API feels familiar like Express but is more type-safe, lighter (~14KB), and requires no custom adapters per platform.
What I like most: Hono doesn’t pretend you’re in Node.js. It uses Web Standard APIs — Request, Response, Headers — the same web standards that browsers, Deno, and Bun all understand natively.
Project Setup
# Create a new project with the Cloudflare Workers template
npm create hono@latest my-api
# Select: cloudflare-workers
cd my-api
npm install
Initial directory structure:
my-api/
├── src/
│ └── index.ts # Entry point
├── wrangler.toml # Cloudflare Workers config
├── package.json
└── tsconfig.json
Basic Routing and Type-safe Responses
File src/index.ts:
import { Hono } from 'hono'
const app = new Hono()
// Simple route
app.get('/', (c) => c.text('Hello from Edge!'))
// Route with path parameter — type-safe
app.get('/users/:id', (c) => {
const id = c.req.param('id') // TypeScript knows `id` is a string
return c.json({ userId: id, status: 'active' })
})
// Route that accepts a POST body
app.post('/webhooks/github', async (c) => {
const payload = await c.req.json()
const event = c.req.header('X-GitHub-Event')
if (event === 'push') {
console.log('Push to:', payload.repository?.full_name)
}
return c.json({ received: true }, 200)
})
export default app
Adding Middleware: Authentication, CORS, and Logging
Built-in middleware is one of Hono’s strengths — no extra npm install required. Example with Bearer token auth, CORS, and logging:
import { Hono } from 'hono'
import { bearerAuth } from 'hono/bearer-auth'
import { logger } from 'hono/logger'
import { cors } from 'hono/cors'
const app = new Hono()
// Global middleware — applies to all routes
app.use('*', logger())
app.use('*', cors({
origin: ['https://yourdomain.com'],
allowMethods: ['GET', 'POST', 'PUT', 'DELETE'],
}))
// Protected routes — only applies to /api/*
app.use('/api/*', bearerAuth({ token: 'your-secret-token' }))
app.get('/api/data', (c) => {
return c.json({ message: 'Protected data', timestamp: Date.now() })
})
// Public route — no auth required
app.get('/health', (c) => c.json({ ok: true }))
export default app
Environment Variables and Secrets
Secrets in Cloudflare Workers are different from Node.js — there’s no traditional .env file. Instead, use Wrangler to set them directly:
# Set a secret via CLI (you'll be prompted to enter the value)
npx wrangler secret put API_SECRET_KEY
# wrangler.toml — declare regular variables (not secrets)
[vars]
ENVIRONMENT = "production"
Access them in code with type-safe bindings:
// Declare types for environment bindings
type Bindings = {
API_SECRET_KEY: string
ENVIRONMENT: string
}
const app = new Hono<{ Bindings: Bindings }>()
app.get('/config', (c) => {
// c.env is fully typed — IDE autocompletes variable names correctly
return c.json({ environment: c.env.ENVIRONMENT })
})
Splitting Routes into Modules as the Project Grows
// src/routes/users.ts
import { Hono } from 'hono'
const users = new Hono()
users.get('/', (c) => c.json({ users: [] }))
users.get('/:id', (c) => c.json({ id: c.req.param('id') }))
users.post('/', async (c) => {
const body = await c.req.json()
return c.json({ created: true, data: body }, 201)
})
export default users
// src/index.ts — mount sub-routers
import { Hono } from 'hono'
import users from './routes/users'
import webhooks from './routes/webhooks'
const app = new Hono()
app.route('/users', users) // /users, /users/:id
app.route('/webhooks', webhooks) // /webhooks/github, /webhooks/stripe
export default app
Local Testing and Deploy
# Run locally with hot reload
npx wrangler dev
# API runs at http://localhost:8787
# Deploy to Cloudflare (first time requires login)
npx wrangler login
npm run deploy
# Output:
# ✅ Deployed to: https://my-api.your-username.workers.dev
Before deploying, I usually run Wrangler dev to test locally, then copy the response into toolcraft.app/en/tools/developer/json-formatter to format and inspect the JSON structure — much more convenient than reading raw output in the terminal or installing an extension. Especially when responses are deeply nested, a clean formatted view makes debugging significantly faster.
The entire deploy process takes about 10–15 seconds. No server configuration, no SSL to worry about (automatic via Cloudflare), no Nginx or PM2 to set up.
Real-World Results: From $5/Month VPS to Nearly $0
After migrating a few internal APIs from VPS to Cloudflare Workers, I noticed a few immediate differences:
- Free plan: 100,000 requests/day — enough for most internal tools and small webhook handlers
- Lower latency for users across multiple regions since requests are handled at the nearest PoP
- Zero maintenance: no OS updates to worry about, no process crashes at 3am
- Deploy and rollback with a single command; Cloudflare maintains deployment history
But there are cases where Cloudflare Workers isn’t the right fit. If your API needs Postgres with complex connection pooling, requires long-running processes, or needs filesystem access — you still need a traditional server. For webhook handlers, API proxies, auth services, and rate limiters, it’s the opposite — far leaner than a 24/7 VPS sitting idle.
The most practical starting point: take a webhook handler you’re currently running on a VPS, port it to Hono, and deploy it to Cloudflare Workers. It takes 2–3 hours, and that VPS will become something you’ll wonder why you kept for so long.

