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
- Taser.js First: Taser.js evaluates requests against your
src/routes/directory. - Express Fall-Through: If no Taser.js route matches, the request automatically falls through to your Express application.
- 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 -y2. Configure src/server.node.ts
Create src/server.node.ts exporting your Express application:
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:
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
/usersrun through Taser.js with complete type safety. - Requests to
/express-legacyexecute your Express controller.
Incremental Migration Strategy
When migrating a large Express codebase to Taser.js:
- Move shared database pools and Redis clients into
src/context.ts. - Move authentication middleware into root layout
src/routes/$.ts. - Incrementally port controllers into verb files inside
src/routes/. - Keep complex legacy routes in
src/server.node.tsuntil 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
Native Fetch Frameworks
Run Taser.js alongside any Web Standard or Fetch-native host framework (Hono, Elysia, HatTip, or native Web Fetch handlers) using host pass-through dispatching.
Fastify Integration
Pair Taser.js file routing with Fastify. Coexist with Fastify plugins, hooks, and native route handlers using host pass-through architecture.