A Node.js module to programmatically execute Express middleware and route handlers without making network requests. It simulates a client calling REST APIs internally, allowing direct invocation of endpoints from code with support for custom query parameters, body, HTTP method, cookies, and response redirect tracking. Current stable version is 0.9.10 (last published in 2018). It has low maintenance activity, with no recent updates. Key differentiator: enables server-side execution of Express routes without requiring a listening server, useful for testing or reuse of logic.
npm install run-middlewareVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage: setting up Express, requiring run-middleware to attach the method, then calling app.runMiddleware on a route to get the simulated response.
Consider using supertest or direct function calls instead.
Be aware that app.runMiddleware is added after require; avoid accidentally overriding it.
Parse body if needed: const parsed = typeof body === 'string' ? JSON.parse(body) : body;
Wrap in a Promise if needed: new Promise((resolve, reject) => app.runMiddleware(path, (code, body) => resolve({code, body})));Add `require('run-middleware')(app)` right after creating the Express app.Use `app.runMiddleware('/path', { query: {}, body: {} }, callback)` — path must be first argument.Do not call app.listen if only testing routes; runMiddleware does not require a listening server.
No dependency data recorded yet.