How to Integrate frontend to backend in MERN stack?
For integrating the frontend to backend just do two things.
Step1: Go and install cors on both side (front end as well as backend)
To install cors simply open the folder into terminal and type npm install cors--save.
step 2: just go to your front end section(react app) open package.json file.
and just add one line into package.json file.
"proxy":"http://localhost:4000"
here i am using 4000, so what is 4000 ?. this is the port on which our backend is listening. so it may be possible that u may have other port number on which your server is listening. so put yours port number on which your backend server is listening. and this proxy thing we have to add in frontend part not in backend part.
Now it may be possible that you want to know about cors.
so basically cors(Cross origin resource sharing) is a package. and by using this package we can communicate with other servers or we can send our data or files among each other. so it is basically a middleware. which makes us able to inetract with applications which is running on different ports.
Comments
Post a Comment