A simple mock middleware for Express.js that allows you to define mock API responses in separate JavaScript files. Version 0.0.6 is the latest and stable release. It uses a glob pattern to load mock files (e.g., 'mock/**/*.js') where each file exports an object mapping HTTP methods and paths to handler functions. The middleware intercepts matching requests and returns mock data without requiring a real backend. It is a lightweight alternative to full mocking libraries, focusing on simplicity and ease of use. The package has minimal dependencies and is suitable for development and testing environments.
npm install express-mock-middlewareVerified import paths — ran on the pinned version, not inferred.
Shows how to set up express-mock-middleware with a glob pattern to load mock files and start an Express server.
Pass cwd: __dirname in options to base path on the current file.
Use exact format: 'GET /api/info' or 'POST /api/submit'.
Use callback-style middleware or provide a synchronous response.
Consider using a more actively maintained mocking library like 'express-mock-api' or 'msw'.
Ensure app.use(mockMiddleware(...)) is placed before app.get(...) or other routes.
Use: const mockMiddleware = require('express-mock-middleware'); or import mockMiddleware from 'express-mock-middleware';Run: npm install globby --save-dev
Pass cwd: __dirname in options and ensure the mock directory exists relative to that path.
Ensure key is exactly 'GET /api/info' (space between method and path).