# Getting started

## 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

```bash
$ mkdir backend-mock
$ cd backend-mock
```

Once the project is created, initialize npm

```bash
$ npm init
```

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

```bash
$ npm install mock-json-response
```

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

```bash
$ mkdir functions
$ mkdir data
```

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

{% code title="/backend-mock/index.js" %}

```javascript
const logicalDir = __dirname + '/functions';
const dataDir = __dirname + '/data';

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

{% endcode %}

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

{% code title="functions/hello.js" %}

```javascript
module.exports = {
    logic: function ({ headers }, { data }) {
        // logic for data manipulation comes here
    },
    request: {
        method: "GET",
        urlPath: "/mock/test"
    },
    response: {
        status: 200,
        inlineData: {
            message: 'Hello world'
        }
    },
};
```

{% endcode %}

Now start the program:

```bash
$ node index.js
```

and wait for the server to start up

```bash
Loading routes...
loaded hello.js
Server started
```

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

```bash
curl -X GET http://localhost:3000/mock/list
```

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

```javascript
{message:'Hello world'}
```

You have successfully, setup backend mock.
