robmax
robmax

Reputation: 352

Display image with Pug/Jade and node.js

I want to display an avatar of the logged user in the navbar, but everytime I get error 404 with the URL: http://localhost:3000/uploads/avatars/avatar_test3.jpeg my pug code is:

ul.nav.navbar-nav.navbar-right
        if user
          li
            a(href='/photos/add') Add photo
          li
            a(href='/users/edit')
              img(src=user.avatar)
          li
            a(href='/users/logout') Logout

user.avatar gives me: uploads/avatars/avatar_test3.jpeg I have also tried with the:

The same error every time

The directory hierarchy:

/
 -uploads
    -avatars
       -avatar_test3.jpeg
  -views
    -layout/pug //the template I'm using 

I also have tried with move the avatar_test3.jpeg file directly to the view directory but without any success.

How can I resolve it?

Upvotes: 0

Views: 1638

Answers (1)

Darlan
Darlan

Reputation: 46

Which error are you getting? If it is http 404, you should turn your uploads folder public through express: http://expressjs.com/en/starter/static-files.html

Something like:

app.use('/uploads', express.static('uploads'))

Upvotes: 3

Related Questions