Deploy DB.JSON file with Render
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.

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
Code-slinger, coffee addict, and meme connoisseur. Turning caffeine into code since 2022. Ready to make your website pop!
More from Derrick
Recommended from Medium
[
See more recommendations