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

254
Vistas
Express js: items is not defined, cannot render results from GET route

I am new to express and i am working on a simple application that displays some database items in the view. I wrote a simple route that should render the selected items from the database. The route is the following :

      //get items in basket shopRoute.js
        router.get("/", (req,res)=>{
         let select = "SELECT artikel_name AS name, preis FROM warenkorb_temp"
         dbConn.query(select, (err,result)=>{
             if(err) throw err;
            //console.log(result)
            res.render('/index', {items: result})
        });
});

the templating code is here:

//index.ejs
    <% items.forEach(function(select) { %>
              <div class = wrnkrb-artikels>
                <h3><%= select.name %></h3>
                <h3><%= select.preis %></h3>
            </div>
          <%  }); %>

i get constantly the error, that "items" is not defined when i try to render the solution in the index.ejs. but if I run the template loop in a new file , the results will be rendered.I also want to mention, that i have one GET method already in use in the same rout file, which functions fine on the index.ejs.

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