Express Integration
Add Taser file-based routing to an Express application. Coexist with legacy controllers and middleware using the host pass-through architecture.
Taser 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's type-safe file conventions.
How It Works
- Taser First: Taser evaluates requests against your
src/routes/directory. - Express Fall-Through: If no Taser route matches, the request automatically falls through to your Express application.
- 404 Handling: If neither Taser nor Express handles the request, Taser returns a standard 404 response.
[Incoming Request]
│
▼
[Taser File Routes] ── Match? ──► [Execute Taser 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. Add Taser 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" }] });
});4. Start Development
pnpm dev- Requests to
/usersrun through Taser with complete type safety. - Requests to
/express-legacyexecute your Express controller.
Incremental Migration Strategy
When migrating a large Express codebase to Taser:
- 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.
Next Steps
Native Fetch Frameworks
Run Taser 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 file routing with Fastify. Coexist with Fastify plugins, hooks, and native route handlers using host pass-through architecture.