I am trying to figure out how to use create-react-app with node, most of the tutorials I've ran across don't use create-react-app / just use script tags in their html. How can I use node.js/expressJS with create-react-app. I have seen some uses where the api is on localhost:3001 and react is on localhost:3000 (and then fetches/ makes an xhr call to the api for data). I am confused about a few things, and haven't found answers in the docs, stackoverflows have been non-react-beginner friendly and kind of abrasive. I would love some beginner friendly answers to the some of these:
- How does deploying work with create-react-app and using expressJS/node.js? (I've read things about "proxys" but I don't understand how that works, is there any way I can use create-react-app and node without using two different ports, i.e 3000 and 3001). Also, this is sort of like having two different apps, one solely front end and another solely backend - instead of one full stack application so it definitely feels stranger than any other ui library/framework I've worked with.
- Any sample repositories using both create-react-app and node.js (on the same port, i.e localhost:3000) would be great to see as well).
Thomas Odorfer
The "webserver" functionality of create-react-app is based upon webpack (wepback-dev-server) and not on basic node/express. To change that and to combine it with node/express api inherently, this would probably require a major rewrite in "manual mode" of the create-react-scripts.
An easier solution is to run both in parallel and for the purpose that the client can work on the same port 3000 (to avoid cross-origin), webpack-dev-server can be configured as a proxy for node/express (running on 3001).
A very good tutorial for that could be found at:
fullstackreact.com/articles/using-create-react-ap…