Skip to content

reach2arunprakash/json-server-heroku

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deploy to Heroku

Heroku

Heroku is a free hosting service for hosting small projects. Easy setup and deploy from the command line via git.

Pros
  • Easy setup
  • Free
Cons
  • App has to sleep a couple of hours every day.
  • "Powers down" after 30 mins of inactivity. Starts back up when you visit the site but it takes a few extra seconds. Can maybe be solved with Kaffeine

Install Heroku ( stay in the same folder where you did git clone )

1 . Clone this repo to anywhere on your computer.

git clone https://github.com/reach2arunprakash/json-server-heroku.git

2 . Change db.json to your own content according to the json-server example and then commit your changes to git.

this example will create /posts route , each resource will have id, title and content. id will auto increment!

{
  "posts":[
    {
      "id" : 0,
      "title": "First post!",
      "content" : "My first content!"
    }
  ]
}

4 . Create an account on
https://heroku.com

5 . Install the Heroku CLI on your computer:
https://devcenter.heroku.com/articles/heroku-cli

6 . Connect the Heroku CLI to your account by writing the following command in your terminal and follow the instructions on the command line:

heroku login

7 . Then create a remote heroku project, kinda like creating a git repository on GitHub. This will create a project on Heroku with a random name. If you want to name your app you have to supply your own name like heroku create project-name: replace with your own name eg: arun-cool-jsonserver

heroku create <my-cool-jsonserver>

8 . To add remote repo to heroku

heroku git:remote -a <my-cool-jsonserver>

git remote -v

9 . Push your app to Heroku (you will see a wall of code). Do this from your folder where you did git clone of this repo

git push heroku master

10 . Visit your newly create app by opening it via heroku:

heroku open

11 . For debugging if something went wrong:

heroku logs --tail

How it works

Heroku will look for a startup-script, this is by default npm start so make sure you have that in your package.json (assuming your script is called server.js):

 "scripts": {
    "start" : "node server.js"
 }

You also have to make changes to the port, you can't hardcode a dev-port. But you can reference herokus port. So the code will have the following:

const port = process.env.PORT || 3000;

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published