0

I am working on a simple API for searching using NodeJs and express, I coded in my server.js like this

app.get('/enduser/search/:keyword', function (req, res) {
  let keyword = req.body.keyword;
  if (!keyword) {
    return res.status(400).send({ error: true, message: 'Please provide a keyword' });
   }
  dbConn.query("SELECT * FROM user_tbl WHERE cp_1 LIKE =? ", ['%' + keyword + '%'],  (err, results) => {
      if (err) throw err;
      //return res.send({ err: false, data: results, message: 'Enduser search list.' });
      return res.status(200).json({"status": 200, "err" : null, "data": results});
  });
});

I got no errors when running on terminal, but i cannot get response when testing the API using postman. When I try to test using postman ... i got the error like this: enter image description here

I tried some methods but still cannot figure out whats wrong.

3
  • user_tbl do not contain cp_1 column Commented Feb 25, 2020 at 6:05
  • You have an error in SQL query Unknown column cp_1 also please use try-catch to avoid the unexpected crashing expressjs.com/en/guide/error-handling.html Commented Feb 25, 2020 at 6:06
  • @AbhaySehgal my db has cp_1 column in user_tbl ... Commented Feb 25, 2020 at 6:11

1 Answer 1

1

First of all, its a bad practice to throw the error. You should always respond to user when developing a backend. Last thing you want is a timeout. I would say respond with error code 500.

Secondly, it seems like the problem in your db. That column doesn't exist. double check and confirm its actually there. Error 1054 refers to unknown column exception.

Also you can refer to this stackoverflow for a question with similar error code but on database side

https://dba.stackexchange.com/questions/162900/mysql-update-query-error-code-1054-unknown-column-in-field-list

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.