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

108
Views
Express JS get function without asking user for an id

I'm having a problem with my get function for my express api. When testing it on postman, the request only works when the user inputs an oid in. However what im trying to do should just show the data from the whole table.

Here's my code, ive been trying to get the get to work without the oid's by using some tutorials but they've not been very good at explaining the whole thing.

async function getComments(req) {
   let status = 500, data = null;
   try {
      const oid = req.query.oid;
      if (oid
         && oid.length > 0 && oid.length <= 32
         && oid.match(/^[a-z0-9]+$/i)) {

         const sql = 'SELECT * FROM products';
         const rows = await db.query(sql, [oid]);

         if (rows) {
            status = 200;
            data = {
               'oid': oid,
               'productName': rows,
               'productCondition': rows,  
               'productDescription': rows,
               'productLocation': rows,

            };
         } else {
            status = 204;
         }
      } else {
         status = 400;
      }
   } catch (e) {
      console.error(e);
   }
   return { status, data };
}


app.get('/demo', async (req, res) => {
   const { status, data } = await getComments(req);
   res.status(status);
   if (data) res.json(data);
   else res.end();
})
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!