Framework Adapters

Express Integration

Add Taser.js file-based routing to an Express application. Coexist with legacy controllers and middleware using the host pass-through architecture.

Taser.js integrates with Express applications using the Host Pass-Through Architecture. You can keep your existing Express routes, controllers, and middleware active while writing all new endpoints with Taser.js's type-safe file conventions.


How It Works

  1. Taser.js First: Taser.js evaluates requests against your src/routes/ directory.
  2. Express Fall-Through: If no Taser.js route matches, the request automatically falls through to your Express application.
  3. 404 Handling: If neither Taser.js nor Express handles the request, Taser.js returns a standard 404 response.
[Incoming Request]
       │
       ▼
[Taser.js File Routes] ── Match? ──► [Execute Taser.js Handler]
       │ (No match)
       ▼
[Express Host App] ─── Match? ──► [Execute Express Route / Middleware]
       │ (No match)
       ▼
[404 Not Found]

Quickstart

1. Scaffold with Express Host

pnpm create taserjs@latest my-express-app --framework express -y

2. Configure src/server.node.ts

Create src/server.node.ts exporting your Express application:

src/server.node.ts
import express from "express";

const app = express();

// Standard Express middleware:
app.use(express.json());

// Legacy or host Express routes:
app.get("/express-legacy", (req, res) => {
  res.json({ message: "Hello from legacy Express route!" });
});

export default app;

3. Import the Compiled Taser.js App (optional host wiring)

When you need the runnable instance (custom adapters, tests), import it from the generated manifest:

import { app } from "./.taserjs/routes.gen.js";

export default app; // Hono instance compiled from defineTaser() + src/routes/

4. Add Taser.js Routes

Create src/routes/users.get.ts:

src/routes/users.get.ts
import { json } from "@taserjs/router/reply";
import { t } from "@taserjs/router";

const GET = t.get("/users");

export default GET.handler(() => {
  return json({ users: [{ id: "1", name: "Alice" }] });
});

5. Start Development

pnpm dev
  • Requests to /users run through Taser.js with complete type safety.
  • Requests to /express-legacy execute your Express controller.

Incremental Migration Strategy

When migrating a large Express codebase to Taser.js:

  1. Move shared database pools and Redis clients into src/context.ts.
  2. Move authentication middleware into root layout src/routes/$.ts.
  3. Incrementally port controllers into verb files inside src/routes/.
  4. Keep complex legacy routes in src/server.node.ts until ready to migrate.

Full Express Migration Guide

For a comprehensive walkthrough of controller conversions, middleware mapping, and known limitations, read the dedicated Migration Guide.


Next Steps