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

888
Views
node js express, ¿cómo res.renderizar una imagen? ¿O pasar una URL de imagen?

Quiero tener un código que cree un texto basado en el número dado por el usuario y también quiero diferentes íconos/imágenes para esto.

Las imágenes se guardan en mi carpeta public/images.

No quiero usar ningún javascript del lado del cliente, así que sin document.getElemntyById, etc. Pensé si es posible pasar una imagen cuando renderizo una página:

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

y luego en mi pug:

 p MY IMAGE: #{image}

o

 img(src="#{imgURL}")

Estoy bastante seguro de que el segundo debería funcionar, pero no carga la imagen...

Entonces, mi pregunta, ¿cómo puedo lograr la forma en que acabo de describir sin client-js? Y si no es posible, ¿cómo puedo lograrlo de otra manera?

por cierto, tengo dos javascripts, uno app.js donde recibo solicitudes de publicación/obtención (allí también necesito mi segundo js) y el segundo para cambiar el número a texto e imagen:

transformarNúmero.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

Puedes enviar la imagen como un archivo.

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

Verifique la referencia: http://expressjs.com/en/api.html#res.sendFile

Si desea representar una plantilla con una imagen, simplemente pase la URL de la imagen a través del backend y tómela en su interfaz:

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

Y entonces:

 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!