The frontend is a React SPA and the backend is NodeJs app that exposes an API. The frontend queries the API for data from time to time but other than that it is fairly independent. What is the best way to host an app like this? Should I include the build folder in the NodeJs app and have the express server serve the static contents from a route? Or should I host both separately, set up a Nginx server for the React app on something like DO? I will host the backend on something like Heroku or Google App Engine. So considering this, what is the ideal solution? What are the pros and cons of either approach?
1 Answer
In case of production, include build folder in the nodejs app.
Performance increase in case production. You can refer react docs for details.
In case of development, host it separately, so its easier to work on it.
2 Comments
Kid Coder
I think you have misunderstood my question a bit. I know about the production build, my question is which is the better solution, should I serve the static files from the same web app that is serving the API or should I host a separate a web server that just serves the static files when requested?
Edwin Babu
Serving the static files from the same web app that is serving the API is the right way. You can check the mern starter code to learn more mern.io