Getting started

Setup your local via NPM

Installation

Mock JSON Response is distributed via node package manager and can be included in your project using package.json

To add the mock-json-response as a project dependency, create a project

$ mkdir backend-mock
$ cd backend-mock

Once the project is created, initialize npm

$ npm init

follow the instruction on the terminal and enter the necessary information, now it time to install mock-json-response

$ npm install mock-json-response

after the package is loaded in your environment, create 2 new folders for data and functions.

$ mkdir functions
$ mkdir data

Its time to launch the app. Before we launch it we need to import module, create an index.js

/backend-mock/index.js
const logicalDir = __dirname + '/functions';
const dataDir = __dirname + '/data';

require('mock-json-response')(logicalDir, dataDir);

Create a JS file in the functions directory: hello.js

Now start the program:

and wait for the server to start up

Now send a request via browser, postman or terminal to localhost:3000/mock/test

The default port of the server is 3000, once the route is hit, you will get the response

You have successfully, setup backend mock.

Last updated

Was this helpful?