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

275
Vistas
Image is not showing on page : nodejs (handelbars)

Trying to show image on page and the address is correct and when clicked on image icon it shows "Cannot GET /images/1640388048496.jpg" Iam using nodejs, express, handelbars and name of image is stored in mongodb and server is running at localhost. enter image description here

In hbs file:

<!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>

In app.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]

File Structure:

enter image description here

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Images should not be directly stored in mongodb as base64, rather it should be saved in s3 or any other cloud storage and then save that link as a string in your database.

If you have a static image you want to show then its best to set it as a static folder in your express app by writing this in your main.js file

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

and then use your images like this:

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