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

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