Hono.js + Node.js REST API
Build an ultra-fast, type-safe REST API with Hono.js and TypeScript on Node.js — with Zod validation, structured error handling, and organized route files.
Initialize the Project
Create a new Node.js project with TypeScript configured for ESM — Hono works best with the native ES Module format.
mkdir my-hono-api && cd my-hono-api && npm init -y && npm install -D typescript tsx @types/nodeConfigure tsconfig.json
Configure TypeScript to compile to ESNext modules, which is required for Hono on Node.js.
Add npm Scripts
Add dev (runs with tsx for hot reload), build, and start scripts to package.json.
Define Zod Schemas
Create src/schemas/user.ts. Centralizing schemas means the same validation rules are used in route handlers and can be re-used for response types.
Create the Users Router
Create src/routes/users.ts. Use @hono/zod-validator to validate request bodies — invalid payloads are rejected before your handler runs, and the parsed data is fully typed.
Create the Main App
Create src/index.ts. Wire up global middleware (logger, CORS, pretty JSON in dev), mount the users router, and add a catch-all error handler.
Start the Development Server
Run the server. tsx watch restarts automatically on file changes — no extra tooling needed.
npm run devTest the API Endpoints
Make a few requests to confirm everything is working. The Zod validator will return a 400 with detailed errors if the body is malformed.
Found this guide helpful? Check out more tools and guides.
Browse All GuidesPrerequisites
- Node.js 22 LTS
- TypeScript familiarity