Node rest emulator
A simple stand alone mock/emulator server that uses rest-emulator.
It serves as a static file server which uses json files to configure the rest responses.
Installation
npm install node-rest-emulator
Usage
Since I created it for my frontend websites which need to mock rest repsonses you can only use it directly or through package.json.
For example npm run mock-server
with your package.json:
"scripts":
If there is any interest I will make it exportable, so you can use codewise.
Configuration
port: 3000 // The directory where all the mock files are (json only), it will traverse the directory recursively dir: '/mocks' // An array of directories to serve static files root: './' corsEnable: true // If set to true it will serve rewriteTemplate for 'GET /' requests rewriteNotFound: false rewriteTemplate: 'index.html' // Custom headers to set for every rest response headers: {};
Example js file
It also supports to read js files. These files will be included through require
.
So you can use functions etc. to configure your responses.
For example:
const _ = ;moduleexports = "/api/random": "GET": "data": _
This configuration will return for each request to api/random
one of those specified numbers.
Example json file
For more information see gulp-rest-emulator and rest-emulator