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

163
Vistas
Node.js render alert

im having a little trouble getting an alert warning to show up on a page when the user inputs a string into a form that is less than some number of characters. The code is working except for actually displaying the error on the actual page. the main app.js has the following function to handle the input error

app.post('/register', 
  body('name').isLength({ min: 5 })
, (req, res)=> {
  const errors = validationResult(req)
  if(!errors.isEmpty()) {

      const alert = errors.array()

      app.get('/store', function(req, res){
        fs.readFile('items.json', function(error, data){
            if(error){
                res.status(500).end()
            }
            else {
                res.render('store.ejs', {
                    items: JSON.parse(data),
                    alert
                })
            }
        })
      })

      console.log('--> length error')
  }
})

The main app.js already has a (below) function to start the store page upon request also.

app.get('/store', function(req, res){ ...

in the store.ejs i have:

        <% if(typeof alert != 'undefined') { %>
            <% alert.forEach(function(error) { %>
                <div class="alert alert-warning alert-dismissible fade show" role="alert">
                    <%= error.msg %>
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                    </button>
                </div>
            <% }) %>
        <% } %>
about 4 years ago · Juan Pablo Isaza
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