Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

885
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda