1

I'm trying to render an image inside an ejs template. I;m doing this:

var pic = "./public/images/"+collection_id+"/"+photo_id+".png";
var comments = "bla bla bla";
res.render('index', { title: 'Viewer' , pic: pic , comments: comments } );

and inside my .ejs

<img src='<%= pic %>' />

I found out however that the true request is

GET /collection/1/photo/public/images/1/1.png 404 1ms

where /collection/1/photo/1 is the URL that I'm trying to route

what can I do in order to render the image inside the template?

mariosk89
  • 944
  • 1
  • 11
  • 31

1 Answers1

-1

Not positive, but I believe express uses the "express.static" term to identify where static content like HTML and images and icons are rooted. Have you set this term in your root js file ... something like:

 app.use(express.static(__dirname + '/public'));

in this example, your static content is rooted in the public directory and your images directory is located within 'public'.

Bob Dill
  • 1,000
  • 5
  • 13