Deploy DB.JSON file with Render

Derrick
2 min readApr 5, 2023

--

You might be working on a project on your bootcamp and you’d want to host your DB.json file online and fetch as an api instead of a local host file. You’ve come to the right place.

Getting Started

  1. Go to https://render.com/ and sign up, it is easier just to link it with your GitHub account.
  2. Give your credit card details, they always refund the cash after SignUp so no stress.
  3. Go ahead and fork, then clone my repository (https://github.com/derrickmomanyi/JSON-SERVER). This is the easier method, I’ve already added all the necessary files. Just change the DB.json and add your data. Then push to github.
  4. If you want to do all the processes yourself, follow the process below.

Adding deployment files yourself

1. Create a folder

mkdir <projectname>-mock-api
cd <projectname>-mock-api

2. Step 1: Create a node js project

npm init -y

3. Install a json server dependency

npm i json-server

4. Create server.js

const jsonServer = require('json-server')

const server = jsonServer.create()

const router = jsonServer.router('db.json')
const middlewares = jsonServer.defaults()

server.use(middlewares)
server.use('/api', router)
server.listen(process.env.PORT || 5000, () => {
console.log('JSON Server is running')
})

5. Create db.json

{
"articles": [
{
"id": 1,
"title": "Example Article",
"content": "This is an example."
},
{
"id": 2,
"title": "Second Article",
"content": "This is also an example."
},
{
"title": "Third Article",
"content": "Another example!",
"id": 3
}
]
}

6. Run the Node JS Project

node server.js

7. Test the API

http://localhost:5000/api/articles

Configuring database with Render

1. Create a new web service

Render WebService

2. Connect your Git repository or use an existing public repository URL

Connect to an existing repository

Since we are using node.js, Render will auto fill the files for you. All you need to add is the name of your api and go to the bottom of the page and click “Create Web Service”.

Result

Build successful

Now go to the created link at the top and voila, you have a running JSON server. Good luck with your project

--

--

Derrick

Code-slinger, coffee addict, and meme connoisseur. Turning caffeine into code since 2022. Ready to make your website pop!