Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

876
Views
node js express, how to res.render an image? Or pass an image url?

I want have a code that creates a text based on user's given number and i want to different icons/images to this too.

The images are saved in my folder public/images.

I want to not use any client-side javascript, so without document.getElemntyById etc. . I thought if it's possible to pass an image when i render an page:

app.get("..", function(req,res){
res.render("page1",{ image: image}     //(or use image url)

and then in my pug:

p MY IMAGE: #{image}

or

img(src="#{imgURL}")

I'm pretty sure second one should work but it doesn't load the image...

So my question how can i achieve the way i just described without client-js? And if its not possible how can i achieve this other way?

btw i have two javascripts, one app.js where i get post/get requests (there i also require my second js) and second one to change number into text and image:

transformNumber.js:

export.modules = {

numberToText: function(number){
var text;
switch(number)
case 2: text = "example";
return text;},

numberToImage: function(number){
var image;
switch(number)
case 1: image = "example image/imageURL";
return image;}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can send the image as a file

app.get('/myimage', function (req, res) {
    return res.sendFile(filepath);
});

Please check the reference: http://expressjs.com/en/api.html#res.sendFile

If you want render a template with image, just pass te image URL via backend and catch it in your frontend:

app.get('/myimage', (req, res) => {
  res.status(200).render('page1', {
    image: 'your_image_with_path.png'
  });
});

And then:

html 
  head 
  body 
      h1 My page with my text
      img=(src=image)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!