This NodeJS module is a delightful mock server built for automation and ongoing development
Run the following command in your terminal:
npm i dmock-server
import { MockServer } from 'dmock-server';
//Initializing the mock server
const server = new MockServer({
hostname: 'localhost',
port: 3000,
routes: [{
method: 'get',
path: '/users',
response: this.users
},{
method: 'get',
path: '/users/:id',
response: (req) => this.getUser(req.params.id)
}]
});
You can setup a function or a simple JS object as a response for a URL.
Once ready, you will need to run server.start()
to start the server and server.stop()
to stop it.