0

i have a mern application in which a person can upload his profile pic. Now once the main page of the app loads i want to show all the users along with their profile picture and a little info. For this to happen the server must return multiple images. How do i achieve this in node js. Sending multiple images to the frontend.

1 Answer 1

1

You can send it to the front-end as a JSON response. Since you didn't provide any code to start with, I assume you are using MongoDB with mongoose.

async function getUsers () { 
   try{
      const data = await User.find()
      const users = data.map((user)=> user)
      res.json({
         users
      })
    }catch(err){
      throw err
   }

The piece of code above returns a JSON response with an array of the user objects if, in your database there an image field, you will get it also in the JSON response while fetching it on the front-end.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.