# How To Deploy a json-server on render

### A short step by step by step guide to creating a JSON-DB server and deploying it on render

`json-server` is a tool for creating mock REST API fast! To get started, ensure you have the following requirements:

1. NodeJS (npm)
    

> ***Let's get started!***

On an empty folder, initiate a nodejs application by running the following on your terminal/CMD:

```javascript
npm init -y
```

Once that is complete, you install the following packages:

* `json-server`
    
* `json-serve`
    
* `cors`
    

```javascript
npm install json-server json-serve cors
```

After the installation, create a new file: `index.js`. This is the entry point for the json-serve. Add the following inside the file:

```javascript
const jsonServer = require("json-server"); // importing json-server library
const server = jsonServer.create();
const router = jsonServer.router("db.json");
const middlewares = jsonServer.defaults();
const port = process.env.PORT || 3001; // you can use any port number here; i chose to use 3001

server.use(middlewares);
server.use(router);

server.listen(port);
```

In the code above, a server has been created that will be fetching and updating data from a json file, `db.json`

In the project root, create a new file: `db.json` and add the following:

```javascript
{
    "feedback": [
        {
            "id": 1,
            "rating": 10,
            "user_name": "Tony Stark",
            "text": "You are the ironman of this world"
        },
        {
            "id": 2,
            "rating": 9,
            "user_name": "Bruce Wayne",
            "text": "You are the batman of this world"
        },
        {
            "id": 3,
            "rating": 8,
            "user_name": "Peter Parker",
            "text": "You are the spiderman of this world"
        }
    ]
}
```

The mock server is ready to run, but let's add some scripts in `package.json`:

Update the `"scripts"` to:

```javascript
  "scripts": {
    "start": "node index.js"
  },
```

## Deploy On Render :-

Go To Site :- [https://dashboard.render.com/](https://dashboard.render.com/)

* Select Web Services
    

![Select Web Services](https://cdn.hashnode.com/res/hashnode/image/upload/v1674052138359/5b853756-db68-4392-a64e-aa703426e4cc.png align="center")

* Connect with Github
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1674052409173/3f177a59-f3ae-4be3-8f08-11f232a196cf.png align="center")

* Go to Github create new repo
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1674052605870/bb8b3d8f-5e33-4f07-b895-7e9785435320.png align="center")

* Clone this repo and create all files and installation of `json-server` all are mentioned in above.
    
* push all the code on `Github`
    
* Go To Render And Select Github Repo where push all json-server code
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1674056944997/011b0184-0bdf-4cd2-81da-23121c010d96.png align="center")

Click on create Web Service Button below

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1674055458069/398c2223-b82b-437d-a747-eab0d1edae73.png align="center")

and wait few minutes for progress and enjoy

Hopefully this article useful for you , happy coding! || Like this article ♥
