
I was exploring free backend hosting options and ran into a common problem: many providers, like Railway, give you a one-time credit rather than a predictable monthly baseline. That makes it hard to plan for ongoing development and testing. I wanted something free, consistent, and modern. That's when I found Cloudflare Workers.
This guide will walk you through the essentials of setting up a minimal backend. By the end, you'll have a clear path to a lightweight, functional CRUD API.
Cloudflare Workers is a serverless platform that runs your code at Cloudflare's global data centers (their "edge"). Instead of a single server or virtual machine, your code executes close to the user, which improves speed and reduces latency.
Think of Workers as a globally distributed runtime for JavaScript, giving your APIs ultra-low latency without worrying about infrastructure.
export default {
async fetch(request) {
return new Response("Hello World", { status: 200 });
}
}
This example illustrates how simple it is to deploy a global endpoint. Users anywhere in the world will hit the nearest edge and get an instant response.
Cloudflare gives a clear free tier, more then enough for mid apps:
Static assets are free and unlimited.
Understanding the free limits upfront helps prevent surprises and lets you plan for realistic workloads. Most personal or mid-scale projects fit comfortably within these bounds.
For a simple CRUD backend, you want something light and fast:
This section compares two popular frameworks suitable for Workers, focusing on footprint, structure, and flexibility.
import { Hono } from 'hono'
const app = new Hono()
app.get('/items', c => c.json([{ id: 1, name: 'item1' }]))
app.post('/items', async c => {
const body = await c.req.json()
return c.json({ id: Date.now(), ...body })
})
export default app
Hono is ideal, mainly for supporting dependent db if you want structure and type safety while keeping the code minimal, It balances simplicity with the ability to grow.
import { Router } from 'itty-router'
const router = Router()
router.get('/items', () => new Response(JSON.stringify([{ id: 1 }])) )
router.post('/items', async (req) => {
const body = await req.json()
return new Response(JSON.stringify({ id: Date.now(), ...body }))
})
export default { fetch: router.handle }
itty-router is perfect for extremely minimal setups. but only lookup to a single table It does routing only and leaves you with only single table. (Does not support relational db)
I would go with hono, always.
Follow these steps to get a minimal backend running:
This section is a practical roadmap. You’ll see how to initialize a project, pick storage, and deploy quickly.
npm install -g wrangler
wrangler generate my-backend
cd my-backend
Pick a framework: Hono for structured data, itty-router for tiny not relational CRUD.
Define your endpoints: /items, /customers, /sales, etc.
Use KV or D1 for storage:
Deploy to Cloudflare:
wrangler deploy
Breaking the process into small steps makes it manageable, even if you’ve never deployed to edge servers before.
Suppose you have entities like:
This is a relational dataset, so using Hono makes managing endpoints and types much easier.
Because this is relational data with relationships between entities, Hono is the better choice. It allows you to:
/coolers, /manufacturers, /purchases, /customers, /sales)Minimal Hono CRUD skeleton for Coolers:
import { Hono } from 'hono'
const app = new Hono()
type Cooler = {
id: string
name: string
tankSize: number
motorType: string
color: string
}
// Create a new cooler
app.post('/coolers', async (c) => {
const body = await c.req.json<Cooler>()
return c.json({ message: 'Cooler created', data: body }, 201)
})
// Get all coolers
app.get('/coolers', async (c) => {
return c.json([{ id: '1', name: 'Symphony', tankSize: 40, motorType: 'BLDC', color: 'White' }])
})
export default app
This example shows how to start structured CRUD development on Cloudflare Workers. Even with relational data, you can remain minimal, fast, and type-safe.
-- Mohammad