title: Try-catch setup in node.js
body: <p>I am trying to setup a <strong>try-catch</strong> for the first time for the following scenario. At the moment I have one inside the <strong>route</strong>, in <strong>server.js</strong> and it does not catch if there is an <strong>error</strong> coming from the <strong>controller</strong>, which is <strong>user.js</strong>. </p>
  
  <p>I am also in doubt if do I need to/can I setup a try-catch also for the controller.</p>
  
  <p>Please help me to setup this properly.</p>
  
  <p>server.js:</p>
  
  <pre><code> app.post('/login-user', (req, res) =&gt; {
          try {
              user.loginUser(req.body, (err, jResult) =&gt; {
                  let token = jwt.sign({
                      user: jResult,
                  }, "supersecret")
                  console.log(jResult)
                  return res.send(token)
              })
          } catch (err) {
              console.log(err)
              return res.send(jResult)
          }        
      })
  </code></pre>
  
  <p>user.js:</p>
  
  <pre><code>user.loginUser = (jUserData, fCallback) =&gt; {
      var aData = [
          jUserData.email,
          jUserData.mobile_number,
          1
      ]
      var sQuery = 'SELECT * FROM users WHERE email = ? AND mobile_number = ? AND active = ?'
      db.each(sQuery, aData, function (err, jRow) {
          console.log(jRow)
          if (err) {
              console.log('BAD, user not logged in')
              return fCallback(true, {
                  status: "INTERNAL SERVER ERROR"
              })
          }
          if (!Object.keys(jRow).length) {
              console.log('NOT FOUND')
              return fCallback(true, {
                  status: "NOT FOUND"
              })
          }
          console.log('GREAT, user logged in')
          return fCallback(false, jRow)
          console.log(jRow)
      })
  }
  </code></pre>