Guilherme Girardi
Guilherme Girardi

Reputation: 71

Is it possible to deploy a ReactJS website with json-server on Netlify?

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!

Upvotes: 7

Views: 7924

Answers (3)

Sean Kelliher
Sean Kelliher

Reputation: 171

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

Upvotes: 1

Ikram Ul Haq
Ikram Ul Haq

Reputation: 51

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

Upvotes: 1

Rishi Bhachu
Rishi Bhachu

Reputation: 172

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

Upvotes: 0

Related Questions