Giter Site home page Giter Site logo

ross-u / deploy-json-server-to-heroku Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 20.0 3 MB

Create your own server/API in minutes. Ready to deploy json-server configuration with a beginner friendly guide.

JavaScript 100.00%
heroku-cli heroku heroku-deployment json json-server server guide tutorial nodejs node simple beginner javascript api

deploy-json-server-to-heroku's Introduction

Deploying a json-server app to Heroku


json-server package

To speed up the initial development of the web apps and creation of the initial MVP, developers sometimes use packages/libraries that enable easy creation of API's without the need to code the entire server structure.

One of such tools is a npm package called json-server.

json-server is a package that can be easily installed and run on the cloud hosting solution and it only requires a properly formated .json file.


Getting Started


This repository includes the complete setup needed for deploying a json-server app to Heroku.

Steps:
  1. Fork and Clone the repository.
  2. Add the custom db.json file.
  3. Deploy json-server app to Heroku.

Fork and clone the repository

Before adding a custom db.json file you should Fork this repo to your user account.

Once done Clone that repo to your local machine by using the link from your own repository.


Add the custom db.json file


db.json file

Once run, json-server loads the provided file db.json and uses it as the database/storage, using the first level property names of the db.json object as the actual server endpoints.


json-server will make these first level properties into server endpoints domain.com/posts, domain.com/comments, domain.com/profile .


Give it a try with the deployed server example.

The below url's belong to the server deployed with the example code in this repo, using the db.json file that you will find in this repo.

Open the below links in your browser or make GET request using Postman, to see how db.json is transformed into server endpoints:




Creating custom endpoints

In order to create custom endpoints on your server, you need to include them in the db.json file.

You can replace the existing db.json file with your own file in order to get custom endpoints and data that will be served.

Only rule that should be observed is that file must be named db.json and be placed in the root directory of the project, as it is in this starter code example.


Deploy json-server to Heroku

Sign up for Heroku

If you don't have a Heroku account you should Sign up / create Heroku account.


Install the Heroku CLI

Check if you have the Heroku CLI installed.

To verify your Heroku CLI installation, use the heroku --version command:

heroku --version

# If already installed you should get something like this:
heroku/7.0.0 (darwin-x64) node-v8.0.0 

If you didn't get the version of Heroku printed in your terminal after executing command heroku --version it means that you don't have the Heroku CLI installed yet on your system.

In that case you should downolad Heroku CLI here and install it, before the next step.


Login to Heroku

After you ensure that Heroku CLI is installed, run the heroku login command.

You’ll be prompted to enter any key to go to your web browser to complete login. The CLI will then log you in automatically.

heroku login

Create a new Heroku app

Before running the below commands, using the terminal navigate to the root directory of the cloned server project.

To create a new Heroku app/project run the command (in order for your app to have a custom name, change the name-of-your-server-app part to include name that you want) from the root directory of the cloned project:

heroku create name-of-your-server-app

Running the above command will create the new Heroku/app project and also add new git remote to the current project, pointing to Heroku which we will use to push the code from our machine to Heroku.

To check the newly added git remote you run the command:

git remote -v

Push to Heroku

This is the final step, which pushes our local code to Heroku dyno which will instantiate the new server and run it automatically.

Commit all the updates and then push to heroku by running the command:

git push heroku master

Done! ✅

Once done you will be able to make the HTTP requests using the URL of your Heroku app and the endpoints created from the db.json.

Visit your Heroku dashboard by visiting https://dashboard.heroku.com/apps to see the newly created (and running) json-server app and the server URL. 😊

deploy-json-server-to-heroku's People

Contributors

dependabot[bot] avatar ross-u avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.