A Full stack stands on the port values of Front - Back ends. Linking the port values are crucial I guess in running a smooth software.
You ever got this β¬β¬ error β¬β¬ then there is a SOLUTION FOR THIS BELOW
π Unhandled Rejection (TypeError): Cannot read property 'error' of undefined (anonymous function) π
Here I am going to tell the important part of linking ends in a stack. While making front to back server requests you should make sure the port values and paths of api are specific. Here I prefer MERN stack for now so ya you can assume :
π‘ FRONT-END : REACT.Js
π‘ BACK-END : NODE.Js
1οΈβ£: BACK-END Node.Js
π΅ You run nodemon app.js
π΅ You run Backend on port 3000
π΅ Backend is active to fetch all requests on port 3000
Good now you are running Backend on port 3000 π
2οΈβ£: FRONT-END React.JS
π΅ You run npm start on your Frontend React.Js
π΅ Your React says something is already running on port 3000
π΅ So you like to change port to say 3001
π΅ Frontend is active on port 3001
Good now you are running Frontend on port 3001 π
3οΈβ£: Create a .env file in FRONTEND
π΅ Open .env file
π΅ Specify a url name say REACT_URL
π΅ Declare REACT_URL=http://localhost:3000
π΅ 3000 port is the same value of your backend active port.
4οΈβ£ DONE FINAL STEP
So while making all the GET POST PUT PATCH DELETE. . . requests from backend to frontend make sure the db is connected and ports that your .env uses is correct to make requests on such routes.
Happy CODINGπ»
Danke for reading π
Top comments (0)