Registry / web-framework / router-middleware

router-middleware

JSON →
library6.1.6jsnpmunverified

An Express-style router for Node.js with full TypeScript safety, including inferred route params from path strings (e.g., '/user/:id' gives req.params.id: string) and typed request/response bodies via generic parameters. Current stable version is 6.1.6. Key differentiators: no view engine, no global state, dual ESM/CJS exports, built-in error handling, and safe defaults (1 MB JSON limit, strict content-type checks). Released actively with regular updates; ships its own TypeScript types.

npm install router-middleware
INSTALL
IMPORT
SIG · ROUTER-MIDDLEWARE
R
router-middleware
web-frameworkjavascriptv6.1.6
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (createApp)
import createApp from 'router-middleware';
const createApp = require('router-middleware');
ESM default export. CommonJS users must use `require('router-middleware').default`.
Router
import { Router } from 'router-middleware';
const { Router } = require('router-middleware');
Named export available for both ESM and CJS.
default (require)
const createApp = require('router-middleware').default;
const createApp = require('router-middleware');
CommonJS requires explicit `.default` due to ESM-first package.

Creates a typed HTTP server with route param inference and typed request/response bodies.

import http from 'node:http'; import createApp from 'router-middleware'; const app = createApp(); const server = http.createServer(app); app.use(app.jsonParser()); app.get<'/user/:id'>('/user/:id', (req, res) => { res.json({ id: req.params.id }); }); app.post<'/user/:id/email', { email: string }, { ok: true; id: string; email: string }>( '/user/:id/email', (req, res) => { res.status(201).json({ ok: true, id: req.params.id, email: req.body.email, }); } ); app.get<'/health'>('/health', (_req, res) => { res.status(200).send('OK'); }); app.useError((err, _req, res, _next) => { res.status(err?.statusCode ?? 500).json({ error: err?.message ?? 'error' }); }); server.listen(5150);
Debug
Known issues
breakingDefault export is ESM-only; CJS require must use .default
fix
Use `const app = require('router-middleware').default;` instead of `const app = require('router-middleware');`
affects: >=6.0.0
breakingChanged from `req.param` to `req.params` for route parameters
fix
Replace `req.param('id')` with `req.params.id`
affects: >=5.0.0
gotchaJSON body parser is not automatic; must be explicitly added with app.use(app.jsonParser())
fix
Add `app.use(app.jsonParser());` before routes that expect JSON body
affects: >=6.0.0
gotchares.send() does NOT accept objects; use res.json() for objects
fix
Use `res.json({...})` instead of `res.send({...})`
affects: >=6.0.0
deprecatedapp.useError() has been renamed to app.onError() in latest v7 beta
fix
Migrate to `app.onError(handler)` when upgrading to v7
affects: 7.0.0-beta
Errors
Common errors & fixes
TypeError: app is not a function
Incorrect import: using require('router-middleware') without .default in CJS
fix
Change to const app = require('router-middleware').default;
Type '{}' is not assignable to type 'string'
Using res.send() with an object instead of res.json()
fix
Replace res.send(obj) with res.json(obj)
Cannot find name 'app'.
Missing app.jsonParser() call or forgot to call createApp()
fix
Ensure `const app = createApp();` is called and `app.use(app.jsonParser());` is added
Property 'params' does not exist on type 'Request'
Route handler not using generic parameter for path, so params is not typed
fix
Add generic type like app.get<'/path/:id'>('/path/:id', handler) to infer params
Upgrade
Version history
6.1.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
8
OpenAI (training)
1
Resources
router-middleware — npm install router-middleware · libregistry