Skip to content

@jaypie/express

Express.js handlers, CORS, and route utilities.

@jaypie/express provides Express.js integration for the Jaypie library, including:

  • Express handler wrapper with lifecycle management
  • CORS configuration
  • Route utilities
  • Request/response helpers
Terminal window
npm install @jaypie/express

Wraps Express.js routes with Jaypie’s handler lifecycle:

import { expressHandler } from "@jaypie/express";
app.get("/api/users", expressHandler(async (req, res) => {
// Handler logic
return { users: [] };
}));

The expressHandler extends the base handler lifecycle with an additional locals phase:

  1. Validate - Request validation
  2. Locals - Populate req.locals with static values or function results
  3. Setup - Resource initialization
  4. Handler - Business logic
  5. Teardown - Cleanup (always runs)

Built-in CORS configuration for Express applications.

Supports testing mode for use with supertest:

import { mock } from "@jaypie/testkit";
import request from "supertest";
const app = mock.expressHandler(handler);
await request(app).get("/api/users").expect(200);

API documentation will be generated from TypeScript definitions.