Skip to content
Advertisement

How to Fetch and Display an Image from an express backend server to a React js frontend?

I’m trying to fetch images from an express backend and display them in the react js frontend. How can I achieve this perfectly?

I have tried to fetch the images saved in my backend folder named “Backup” and display them back to the user in the react js frontend. I have tried this using axios but still am getting an invalid image instead of the correct image.

Below is my fetch request in the frontend.

JavaScript

And this what I have in the server.js file in the backend

JavaScript

I expect the Image to show up in the users page. Thanks.

Advertisement

Answer

This worked for me:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement