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

279
Views
La imagen no se muestra en la página: nodejs (handelbars)

Intentando mostrar la imagen en la página y la dirección es correcta y cuando se hace clic en el ícono de la imagen, se muestra "No se puede OBTENER /images/1640388048496.jpg" Estoy usando nodejs, express, handelbars y el nombre de la imagen está almacenado en mongodb y el servidor se está ejecutando en localhost . ingrese la descripción de la imagen aquí

En el archivo hbs:

 <!DOCTYPE html> <html lang="en"> <head> {{>header}} </head> <body> {{>navbar}} <div class="container"> <div class="box"> <div class="heading"> <h2>{{questions.title}}</h2> </div> <hr> <div class="descrip"> <p>{{{questions.description}}}</p> </div> <img src="../../images/1640388048496.jpg" alt="Image"> <hr> <p>Posted By {{questions.postedBy}}</p> <div class="comment-box"> <form action="/show/{{questions._id}}/comments" method="post"> <textarea name="comment" id="editor1"> </textarea> <button type="submit">Your Answer</button> </form> </div> <div class="people_list"> <h1>{{questions.comments}}</h1> {{#each questions.comments}} <div class="ans"> <p>{{this.comment}}</p> <p>{{this.dateposted}}/{{this.monthposted}}/{{this.yearposted}}</p> </div> {{/each}} </div> </div> </div> <script src="./ckeditor/ckeditor.js"></script> <script> CKEDITOR.replace('editor1'); </script> </body> </html>

En aplicación.js:

 [![app.get('/show/:id', (req,res)=>{ var db = req.db; Question.findById(req.params.id).populate('comments').exec( function(err, question){ res.render('show', { questions: question, }) }); })][1]][1]

Estructura del archivo:

ingrese la descripción de la imagen aquí

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Las imágenes no deben almacenarse directamente en mongodb como base64, sino que deben guardarse en s3 o en cualquier otro almacenamiento en la nube y luego guardar ese enlace como una cadena en su base de datos.

Si tiene una imagen estática que desea mostrar, es mejor configurarla como una carpeta estática en su aplicación express escribiendo esto en su archivo main.js

 app.use(express.static(path.join(__dirname, "images")));

y luego usa tus imágenes así:

 <img src="/1640388048496.jpg" alt="Image">
about 4 years ago · Santiago Trujillo 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!