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

350
Views
How to fix problem with throwing error in Node.js

Here is a piece of Node.js code

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

console.log(req.query.id);

let catID = req.query.id;

res.render('category',{});
con.query(
  'SELECT * FROM category WHERE id = '+catID,
  function (error, result) {
    if(error) throw err;
    console.log(JSON.parse(JSON.stringify(result)));
  });
});

My problem

Don't know what is this and how to fix it

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are receiving err but trying to throw error. Use below code.

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

console.log(req.query.id);

let catID = req.query.id;

res.render('category',{});
con.query(
  'SELECT * FROM category WHERE id = '+catID,
  function (error, result) {
    if(error) throw error;
    console.log(JSON.parse(JSON.stringify(result)));
  });
});

Disclaimer: Use parameterized query instead of adding query param to db queries. Current code will cause SQL injection threat.

about 4 years ago · Juan Pablo Isaza Report
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!