search

Home  >  Q&A  >  body text

Way to get image from Express.js and display image in React

I created a registration form that gets data from the user and their profile picture and stores the image into a public folder in my server. The path structure is server/public/avatar but the problem is express.static doesn't work for me, it gives me the error of Connot Get I have tried this syntax app.use(express.static('public')); = doesn't work app.use(express.static(path.join(__dirname, 'public'))); = does not work app.use('/avatar',express.static(path.join(__dirname, '../public/avatar'))); = not working app.use('/avatar',express.static(path.join(_dirname '../public/avatar'))); = not working This is my API http://localhost:3001/avatar/avatar_url.jpg Please help me solve my problem, I'm very new to Nodejs and React

I want to get the user's profile picture and use the mapping function to display their profile into my react, here is my code to get the profile picture in the react http://localhost:3001 /avatar/${value?.avatar_url}}/> {value.first_name} {value.last_name}

P粉351138462P粉351138462437 days ago1215

reply all(1)I'll reply

  • P粉481366803

    P粉4813668032023-09-17 12:57:41

    I solved my problem, I just added this code app.use(express.static('public')); to my index.js file

    reply
    0
  • Cancelreply