0

I have a project with React front end and Node backend using ExpressJS. The backend server basically just returns a json that I can fetch data on my front end. On back end, there is a xml file. So the whole process is convert xml->json on express backend, then fetch data from express backend on react front end.

When I do node index.js to start the server, and do npm start to start my front end, everything works perfect, the front end renders all data.

Then I wanted to deploy this project on Heroku. I put all files into one directory and seperate with client and server directories. Then I npm start build the code in react. In my index.js file of backend, I have

app.use(express.static(path.join(__dirname + '/public')))

and then I copied and pasted build files into the public directory in my server directory. I should be supposed to run the app by node index.js, the app worked, however, the data was not read. Is that because I only started the front end but did not start the server so I didnt get any data? How do I fix this?

Alex Zhang
  • 13
  • 2
  • You should modify your package.json, one way of achieving this is called "monorepo" and you have a great how-to answer in here: https://stackoverflow.com/a/71521749/12737879 On a side note if you are a student & on a free tier of Heroku, I wanna remind you that Heroku's free tier ends in 5 days (Nov 28 2022) so you rather look up for Heroku alternatives. – Aleksandar Nov 23 '22 at 04:38

0 Answers0