Connection error in mern stack

I am following the Exercise Tracker app on your youtube channel . I have a problem to connect the frontend with the backend . when i try to create a user and i console log it . It show the object {username: “amr”} , but it doesn’t send the req in axios.post . I checked the server connection and the database connection and there is nothing wrong . I also use insomnia and there is no problem when i post the user the json object is created in mongodb database . This is the error
Error: Network Error
at createError (createError.js:17)
at XMLHttpRequest.handleError (xhr.js:80)
OPTIONS http://localhost:5000/user/add net::ERR_CONNECTION_REFUSED xhr.js:166

I am not familiar with the exercise tracker project directly, but it sounds like your error is with axios and how you setup your project.

The error your getting looks like axios is not able to call the endpoint, this could be one of the following:

  1. The back-end server isn’t on port 5000
  2. The url you are calling isn’t right
  3. The back-end server isn’t running (I kinda doubt it, but its worth mentioning)
  4. Your network doesn’t allow this (for some unknown reason)
  5. If you are using a dev server it needs to have a proxy to be able to call other ports on your system (at least this is what Ive seen with stuff I work with)

If insomnia is working and able to call the back-end of your stack, I’d double check your client-side setup as its probably not setup correctly to call your back-end. You could also call your back-end from your browser directly by calling a GET endpoint by putting in the url to your browser and see what comes back.

Good luck :slight_smile:

1 Like

You were right , i ran the frontend and i forget about the backend but thank you :smile:

1 Like