Deploying Fake Back-End Server & DataBase Using JSON-SERVER, GitHub, and Heroku

Overview

Deploying Fake Back-End Server & DataBase Using JSON-SERVER, GitHub, and Heroku.

In this article, we will create and host a fake server that we can deal with it as a normal Back-End Server and use all the CRUD Operations using HTTP requests.

1.Creating the Fake Server.

You can download the final result HERE, Or follow along with me.

  • Create a folder and name it fake-server.
  • Open the terminal and init npm, and make the entry point server.js
npm init
npm i json-server
  • Add a start script.

package.json

{
  "name": "fake-server",
  "version": "1.0.0",
  "description": "fake server with fake database",
  "main": "server.js",
  "scripts": {  // <===
    "start": "node server.js" // <===
  },
  "author": "Youssef Zidan",
  "license": "ISC",
  "dependencies": {
    "json-server": "^0.16.3"
  }
}
  • create .gitignore file and add node_modules. .gitignore
node_modules
  • Create server.js file and paste the following
const jsonServer = require("json-server");
const server = jsonServer.create();
const router = jsonServer.router("db.json"); // <== Will be created later
const middlewares = jsonServer.defaults();
const port = process.env.PORT || 3200; // <== You can change the port

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

server.listen(port);
  • init git and publish your repo to GitHub
git init
git remote add origin https://github.com/<YourName>/<Repo-Name>.git
git add .
git push --set-upstream origin master

Download the final Repo from HERE

2. Creating the DataBase

  • Create db.json file
  • Fill in any data you like, I use Mockaroo to generate dummy data.

db.json

{
  "users": [
    {
      "id": 1,
      "first_name": "Justina",
      "last_name": "Ginglell",
      "email": "[email protected]",
      "gender": "Female"
    },
    {
      "id": 2,
      "first_name": "Marion",
      "last_name": "Jenman",
      "email": "[email protected]",
      "gender": "Male"
    },
    {
      "id": 3,
      "first_name": "Alfy",
      "last_name": "Begin",
      "email": "[email protected]",
      "gender": "Female"
    },
    {
      "id": 4,
      "first_name": "Karney",
      "last_name": "Zanussii",
      "email": "[email protected]",
      "gender": "Male"
    },
    {
      "id": 5,
      "first_name": "Reid",
      "last_name": "Schapero",
      "email": "[email protected]",
      "gender": "Male"
    },
    {
      "id": 6,
      "first_name": "Dorine",
      "last_name": "Braybrookes",
      "email": "[email protected]",
      "gender": "Female"
    },
    {
      "id": 7,
      "first_name": "Sarena",
      "last_name": "Frape",
      "email": "[email protected]",
      "gender": "Female"
    },
    {
      "id": 8,
      "first_name": "Malva",
      "last_name": "Pierse",
      "email": "[email protected]",
      "gender": "Female"
    },
    {
      "id": 9,
      "first_name": "Rania",
      "last_name": "Dablin",
      "email": "[email protected]",
      "gender": "Female"
    },
    {
      "id": 10,
      "first_name": "Ingrim",
      "last_name": "Offen",
      "email": "[email protected]",
      "gender": "Male"
    }
  ]
}
  • Push your work
git add .
git commit -m "creating the database"
git push

3. Creating the server

  • Create account on Heroku
  • Install the Heroku CLI on your computer
  • Open the terminal and log in then follow the instructions
heroku login
  • Create a project
heroku create fake-server
  • Push your app to Heroku
git push heroku master
  • Open your created app
heroku open

You will see something like this:

Heroku App

Now, You can access and modify resources via any HTTP method GET POST PUT PATCH DELETE OPTIONS

4. Creating a Pipeline.

A pipeline is simply a connection between your GitHub repo and your Heroku Project. So, Whenever you update your db.json for example and push your changes to a specific branch Heroku will be listening to this branch and build your app with the updated database.

  • Open your dashboard on Heroku and choose your app.

Alt Text

  • Navigate to Deploy tap and create a pipeline, Connect your GitHub with the fake-server repo

Alt Text

  • Configure auto-deploy and choose the branch of the Pipeline

Alt Text

Now whenever you push the changes to the selected branch, the database will be updated and can be accessed via the same base API.

You might also like...

E-commerce Back-end Server

Ecommerce Backend Server This project contains the intial setup needed for creating the MVC folder for our Ecommerce-backend application and setting u

Feb 10, 2022

RESTful API using Hapi NodeJs Framework. This app is project from Dicoding Couses, Belajar Membuat Aplikasi Back-end untuk Pemula

RESTful API using Hapi NodeJs Framework. This app is project from Dicoding Couses, Belajar Membuat Aplikasi Back-end untuk Pemula

Jan 3, 2022

This shows NFT tracking in the certain wallet using express back-end.

nft-tracking-for-solana-wallet Express backend for NFT tracking in the certain wallet. Webhook for scraping secondary marketplace information for part

Nov 16, 2022

End-to-End sync Linear.app and GitHub

End-to-End sync Linear.app and GitHub

Initially created by Spacedrive, now maintained by Cal.com and Neat.run Linear to GitHub Sync This is a system to synchronize Linear issues to GitHub

Jan 3, 2023

Deploy the latest ghost v4 on Heroku

Ghost 4.X on Heroku Ghost is world's most popular modern publishing platform for creating a new media platform. It has been used by Apple, SkyNews, Bu

Dec 15, 2022

24/7 Steam ingame time idler with Heroku (simple version)

simple-steam-idler-heroku 24/7 Steam ingame time idler with Heroku (simple version) Requirements: Install Git: https://git-scm.com/downloads Install H

Dec 18, 2022

Nodejs,Expreess,Mongodb,Reactjs,Redux,Java app,Google,Docker,Heroku,...

Nodejs,Expreess,Mongodb,Reactjs,Redux,Java app,Google,Docker,Heroku,...

Tiến độ công việc Team: https://docs.google.com/spreadsheets/d/1BBv4CXNniNjqdIE7tjrG9UM4nprd3NSVy2FX9oaWq0Q/edit#gid=0 Web Online: https://movienetfli

Sep 17, 2022

A free and open source api server for app "Fake Location @ 1.3.0.2"

FakeLocation-Server 中文 Introduction A fake api server for FakeLocation App Unlock all apps limitation and you can use pro version permanently for free

Dec 13, 2022

A free and open source api server for app "Fake Location @ 1.3.0.2"

FakeLocation-Server 中文 Introduction A fake api server for FakeLocation App Unlock all apps limitation and you can use pro version permanently for free

Jul 4, 2022
Owner
Israel David
FullStack Software Developer 🧠| Likes Games | Playing Around With Anything Tech-Related 😎 | Gadgets Freak 😫
Israel David
simple PWA catalogue with vanilla javascript and json-server as a fake server

simple PWA catalogue with vanilla javascript and json-server as a fake server

bagher musavi 2 Mar 12, 2022
✏️ A small jQuery extension to turn a static HTML table into an editable one. For quickly populating a small table with JSON data, letting the user modify it with validation, and then getting JSON data back out.

jquery-editable-table A small jQuery extension to turn an HTML table editable for fast data entry and validation Demo ?? https://jsfiddle.net/torrobin

Tor 7 Jul 31, 2022
Personal Blog - a project developed with Angular for the front-end interface and Wordpress for the back-end API served with Docker containers

PersonalBlog This project was generated with Angular CLI version 13.0.1. Front-end Interface Development server Run ng serve or ng serve --configurati

null 9 Oct 5, 2022
It consists of a recreation of Twitter, to put into practice both Front-end and Back-end knowledge by implementing the MERN Stack together with other technologies to add more value to the project.

Twitter-Clone_Back-end ✨ Demo. ?? About the project. ?? Descriptions. It consists of a recreation of Twitter, to put into practice knowledge of both F

Mario Quirós Luna 5 Apr 12, 2022
It consists of a recreation of Twitter, to put into practice knowledge of both Front-end and Back-end implementing the MERN Stack along with other technologies to add more value to the project.

Twitter-Clone_Front-end ✨ Demo. Login Home Profile Message Notifications Deployed in: https://twitter-clone-front-end.vercel.app/ ?? About the project

Mario Quirós Luna 5 Jun 26, 2022
Web-Technology with Aj Zero Coding. In this tutorial we learn front-end and back-end development.

Installation through NPM: The jQWidgets framework is available as NPM package: jQuery, Javascript, Angular, Vue, React, Web Components: https://www

Ajay Dhangar 3 Nov 19, 2022
Pass trust from a front-end Algorand WalletConnect session, to a back-end web service

AlgoAuth Authenticate to a website using only your Algorand wallet Pass trust from a front-end Algorand WalletConnect session, to a back-end web servi

Nullable Labs 16 Dec 15, 2022
A repository to generate the fake json data from protobuf.

Mock Protobuf A command-line tool to mock protobuf! Table of Contents Install Usage Generate Mock Data Mock Server Mock Server Data Filter Include Fil

Jasonkay 9 Dec 7, 2022
JCS (JSON Canonicalization Scheme), JSON digests, and JSON Merkle hashes

JSON Hash This package contains the following JSON utilties for Deno: digest.ts provides cryptographic hash digests of JSON trees. It guarantee that d

Hong Minhee (洪 民憙) 13 Sep 2, 2022
Package fetcher is a bot messenger which gather npm packages by uploading either a json file (package.json) or a picture representing package.json. To continue...

package-fetcher Ce projet contient un boilerplate pour un bot messenger et l'executable Windows ngrok qui va permettre de créer un tunnel https pour c

AILI Fida Aliotti Christino 2 Mar 29, 2022