Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you deploy a fake backend run by json-server NPM module using Heroku?

I often use the npm module json-server to generate a fake JSON api given a db.json file. Is there any way to deploy that to Heroku? Essentially, I just run

json-server --watch db.json

And it runs a server that also servers static html if there are any in the public/ directory. Essentially, I think it is just running a Node server, except I tried pushing to Heroku, but it did not work. Is there a special procedure I should do in order to make Heroku run that json-server module as my server?

like image 972
nbkhope Avatar asked Jul 20 '16 22:07

nbkhope


People also ask

Can I deploy json server to Heroku?

Deploy json-server to HerokuShould only be used in development purpose but can act as a simpler database for smaller applications.


2 Answers

Under the hood, Heroku will look for a startup-script, this is by default npm start so make sure you have that in your package.json.

Late to the party, but in case someone needs, just check out this repo, change the db.json to what you want, then follow step-by-step instructions to deploy to Heroku.

like image 119
bonniss Avatar answered Oct 01 '22 17:10

bonniss


If you want to consume your fake APIs from an application published on Heroku, AWS Elastic Beanstalk etc., use My Json Server https://my-json-server.typicode.com/ . As far as I know, it is free for a small json.db file.

All you need to do is:

  1. Create a repository on gitHub and put your json.db there
  2. Call you API https://my-json-server.typicode.com/<your-github-username>/<your-github-repo>
like image 34
Anton Polkanov Avatar answered Oct 01 '22 15:10

Anton Polkanov