Elysia Connect Middleware

raw JSON →
0.0.6 verified Sat Apr 25 auth: no javascript

A plugin for the Elysia web framework that allows using Express/Connect middleware directly. Version 0.0.6, active development with frequent releases. It bridges Elysia's request/response objects to the Connect interface, enabling reuse of middleware like passport, cors, compression, and session. Key differentiators: lightweight, preserves Elysia's performance, and supports seamless integration without modifying existing middleware. Requires Elysia ^1.3.1.

error Error: connectMiddleware is not a function
cause Incorrect import or using CommonJS require style.
fix
Use ESM import: import { connectMiddleware } from 'elysia-connect-middleware'
error TypeError: Cannot read properties of undefined (reading 'query')
cause Middleware expects req.query from Express, but plugin hasn't parsed URL params.
fix
Ensure you use .use(connectMiddleware()) before any middleware that relies on query parsing.
error Error: Elysia: unknown plugin 'connectMiddleware'
cause Plugin not properly installed or imported.
fix
Run npm install elysia-connect-middleware, and import correctly.
gotcha Some Express middleware that relies on Node.js-specific features (e.g., streaming, raw body parsing) may not work correctly.
fix Test middleware compatibility; prefer middleware that works with standard request/response objects.
gotcha The plugin modifies the request object to include Express-style properties (e.g., req.query, req.body). Ensure no conflicts with Elysia's native handling.
fix Access Express properties via the request object, but be aware of potential overrides.
deprecated Early versions (pre-0.0.2) used a different import pattern; deprecated.
fix Update to latest version and use the current import syntax.
gotcha Multiple middleware must be wrapped in an array or chained; single function passed directly may not be detected correctly.
fix Always pass middleware functions wrapped in an array: .use(connectMiddleware([cors(), compression()]))
npm install elysia-connect-middleware
yarn add elysia-connect-middleware
pnpm add elysia-connect-middleware

Shows basic setup: import Elysia and the plugin, apply middleware, and start server.

import { Elysia } from 'elysia';
import { connectMiddleware } from 'elysia-connect-middleware';

const app = new Elysia()
  .use(connectMiddleware())
  .get('/', () => 'Hello from Elysia!')
  .listen(3000);

console.log('Server running on http://localhost:3000');