Home > database >  Unable to res.send in express
Unable to res.send in express

Time:08-07

Hello I am having issue sending response with express.

I have read in other questions that maybe changing the err, res to other varible may fix this issue but it doesn't.

router.post('/checkPaid', (req, res, next) => {
  db.query(`SELECT email_address FROM users WHERE email_address = ?`, req.body.email_address, (err, res) => {
    if(err)
    {
      throw err
    }
    else
    {
      console.log('User found')
      db.query(`SELECT course_paid FROM users WHERE email_address = ?`, req.body.email_address, (error, results) => {
        if(error)
        {
          console.log(error)
        }
        else
        {
          results.send('test')
        }
      })
    }
  })
})

 throw err; // Rethrow non-MySQL errors
      ^

TypeError: results.send is not a functio

CodePudding user response:

Try using res.send('test') instead of results.send('test'), because res is express response object.

EDIT:

router.post('/checkPaid', (req, res, next) => {
  db.query(`SELECT email_address FROM users WHERE email_address = ?`, req.body.email_address, (err, results) => {
    if(err)
    {
      throw err
    }
    else
    {
        console.log('User found')
        db.query(`SELECT course_paid FROM users WHERE email_address = ?`, req.body.email_address, (error, results) => {
            if(error)
            {
                console.log(error)
            }
            else
            {
                res.send('test')
            }
      })
    }
  })
})
  • Related