Registry / testing / rest-emulator

rest-emulator

JSON →
library0.1.3jsnpmunverified

rest-emulator (v0.1.3) is a lightweight Express/Connect middleware for mocking REST APIs with configurable endpoints, query-based responses, HTTP method support, response codes, headers, and timeouts. Last published in 2017 with no recent updates. Differentiates from tools like json-server by providing a programmatic middleware approach for integration into existing Express apps, supporting file-based mock structures with presets.

npm install rest-emulator
INSTALL
IMPORT
SIG · REST-EMULATOR
R
rest-emulator
testingjavascriptv0.1.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default
import restEmulator from 'rest-emulator'
const restEmulator = require('rest-emulator')
Package has no default export; actually uses module.exports = function, so require is correct import pattern.
restEmulator
const restEmulator = require('rest-emulator')
import { restEmulator } from 'rest-emulator'
Module exports a function directly, not a named export.
middleware
const restInstance = require('rest-emulator')(config); app.use(restInstance.middleware)
const middleware = require('rest-emulator').middleware
Middleware is a property of the instance, not a direct export.

Sets up an Express server with a mock REST endpoint for /api/users returning JSON data.

const express = require('express'); const restEmulator = require('rest-emulator'); const config = { '/api/users': { data: [ { name: 'John' }, { name: 'Adam' } ] } }; const app = express(); const restInstance = restEmulator(config); app.use(restInstance.middleware); app.listen(3000, () => console.log('Server running on port 3000'));
Debug
Known issues
deprecatedPackage is unmaintained since 2017. No security updates or compatibility with modern Express versions.
fix
Consider alternatives like json-server, msw, or miragejs.
affects: all
gotchaThe module.exports is a function, not a named object. Using ES6 import syntax will fail.
fix
Use require() to import the module.
affects: all
gotchaThe middleware must be accessed as a property of the instance (restInstance.middleware), not directly from the module.
fix
Store the result of restEmulator(config) and use .middleware.
affects: all
Errors
Common errors & fixes
TypeError: restEmulator is not a function
Using default import (ESM) instead of require().
fix
const restEmulator = require('rest-emulator');
TypeError: Cannot read property 'middleware' of undefined
Calling restEmulator.middleware directly instead of const instance = restEmulator(config); instance.middleware
fix
Store the instance first, then access .middleware.
Upgrade
Version history
0.1.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Amazon
1
Resources
rest-emulator — npm install rest-emulator · libregistry