DEV Community

Discussion on: Three Stages of My Relationship with React

Collapse
 
dellward profile image
Dell Ward

Thanks! Good luck to you also. How is that going? I'm just learning how to integrate express with React.

Collapse
 
belhassen07 profile image
Belhassen Chelbi • Edited

create-react-app is running on port 3000, express is running on port 3001.
I'm fetching data using fetch('/users')... this will fetch localhost:3000 not localhost:3001 where express is running (and express will send the json data when you're making the ajax request right?) so what I needed to do is to add "proxy" : "localhost:3001" so the ajax request can be "redirected" to port 3001 to get data sent by the express app. If you're feeling dizzy, it may be because you're seeing things. Checkout this : you'll end up by making your first react+express app

Thread Thread
 
nicowernli profile image
Nicolás Wernli

You can pass the entire host to fetch if you need so. fetch('localhost:3001/users'). Maybe if you create a function that adds the host for you and changes de host depending on the environment you are done.