Choorai
Lv.1 Beginner Node.js TypeScript

Build an API in 15 Minutes with Hono

Hono is the lightest Node.js web framework. You can build a complete REST API with just a single file.

Why Hono?

  • Faster and more modern than Express
  • TypeScript support out of the box
  • Edge Runtime (Cloudflare Workers) compatible
  • Almost no boilerplate

1. Create Project

Terminal
mkdir my-api && cd my-api
npm init -y
npm install hono @hono/node-server
npm install -D typescript @types/node tsx

tsx allows you to run TypeScript directly.

2. Write Your First API

src/index.ts
import { Hono } from 'hono';
import { serve } from '@hono/node-server';

const app = new Hono();

// Health check
app.get('/health', (c) => {
  return c.json({
    status: 'ok',
    timestamp: new Date().toISOString(),
  });
});

// Hello API
app.get('/api/hello', (c) => {
  const name = c.req.query('name') || 'World';
  return c.json({ message: `Hello, ${name}!` });
});

// Start server
serve({ fetch: app.fetch, port: 8000 });
console.log('🚀 Server running on http://localhost:8000');

Run

Terminal
npx tsx src/index.ts

# Test
curl http://localhost:8000/health
curl http://localhost:8000/api/hello?name=Choorai

3. Add CRUD API

src/index.ts
import { Hono } from 'hono';
import { serve } from '@hono/node-server';
import { cors } from 'hono/cors';

const app = new Hono();

// CORS configuration
app.use('*', cors({
  origin: ['http://localhost:5173'],
  credentials: true,
}));

// In-memory storage
interface Project {
  id: string;
  name: string;
  description: string | null;
  created_at: string;
}

const projects = new Map<string, Project>();

// List projects
app.get('/api/v1/projects', (c) => {
  const items = Array.from(projects.values());
  return c.json({ items, total: items.length });
});

// Create project
app.post('/api/v1/projects', async (c) => {
  const body = await c.req.json();
  const project: Project = {
    id: crypto.randomUUID(),
    name: body.name,
    description: body.description || null,
    created_at: new Date().toISOString(),
  };
  projects.set(project.id, project);
  return c.json(project, 201);
});

// Get project
app.get('/api/v1/projects/:id', (c) => {
  const project = projects.get(c.req.param('id'));
  if (!project) return c.json({ error: 'Not found' }, 404);
  return c.json(project);
});

// Delete project
app.delete('/api/v1/projects/:id', (c) => {
  const deleted = projects.delete(c.req.param('id'));
  if (!deleted) return c.json({ error: 'Not found' }, 404);
  return c.body(null, 204);
});

serve({ fetch: app.fetch, port: 8000 });
console.log('🚀 Server running on http://localhost:8000');

4. Deploy with Docker

Dockerfile
FROM node:20-slim
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
EXPOSE 8000
CMD ["node", "dist/index.js"]
Terminal
# Local test
docker build -t my-hono-api .
docker run -p 8000:8000 my-hono-api

# Cloud Run deployment
gcloud builds submit --tag gcr.io/YOUR_PROJECT/my-hono-api
gcloud run deploy my-hono-api --image gcr.io/YOUR_PROJECT/my-hono-api

FastAPI vs Hono

Hono (this page)

  • ✅ Unified JavaScript/TypeScript
  • ✅ Same language as frontend
  • ✅ Edge Runtime support
  • ⚠️ Type validation needs manual implementation

FastAPI (Lv.2)

  • ✅ Auto documentation (Swagger)
  • ✅ Pydantic type validation
  • ✅ Python ecosystem (ML/AI)
  • ⚠️ Requires learning a separate language

Full Example Code

Check out the Hono version of the B2B Admin API: examples/b2b-admin/api-hono

Last updated: February 22, 2026 · Version: v0.0.1

Send Feedback

Opens a new issue page with your message.

Open GitHub Issue