6

I have an application built with ReactJS, but I'm using a fake API (json-server) to handle my data.

So, before I run 'npm start' to run the application I have to run 'json-server server.json -p 3333' to run the server and I can't make it run on Netlify.

Does anybody know if it is possible or not?

Thanks!

  • I found [this](https://dev.to/nikita_guliaev/deploying-create-react-app-with-json-server-as-backend-to-github-3pp9) article but uses Github pages instead – Ricardo Sanchez Nov 18 '20 at 08:28

3 Answers3

1

You can run json-server on heroku or glitch. By using that url (provided by heroku or glitch) to fetch json data instead of localhost, you can deploy your website on netlify while your json server would be running on heroku or glitch. You can perform CRUD operations on the website deployed on netlify.

Procedure to upload JSON data on Glitch:

Or skip these steps and use the given url repository to test

For more details, visit: https://github.com/ikramdeveloper/json-server-deploy

  • 1
    Live example: https://reactjs-easy-peasy-blog.netlify.app/ and json-data is here https://seemly-truthful-scribe.glitch.me/posts – Ikram Ul Haq Apr 16 '22 at 00:45
1

I ran into this issue as well. I discovered that you cannot run a JSON server on Netlify.

You can use something called Netlify Functions as a workaround. I believe each function mimics a server request. Each has its own URL and when you call a function, the Netlify server returns a JSON response.

Here is a Netlify forum that discusses it. https://answers.netlify.com/t/json-server-doesnt-work-on-netlify/32351

0

You can run JSON server on Heroku, that way you wont need to run both React and JSON server, as JSON server will already be running on a separate server at Heroku.

Its also free to run JSON server on Heroku too; https://github.com/eecs130/json-server-heroku#create-your-database

Once you have deployed JSON server on Heroku, your path then will be your db.json Resource name (example below is 'blogs');

    {
  "blogs": [
    {
      "postTitle": "My First Blog",

So your db.json REST API path to post to from your running instance of react will be; https://xxxx.herokuapp.com/blogs

Rishi Bhachu
  • 162
  • 2
  • 10