title: Is this right way to release the connection?
body: <p>As you know Node.js statements are async. So I write code in following way. But I can't make sure if the connection is released or not.</p>
  
  <p>Why, because I'm writing <code>connection.release()</code> just after <code>res.json()</code>. In my view, once we send response the control doesn't pass to next statement (Query <strong>1</strong>: Is it true?). So should I write it before I send response?</p>
  
  <p>Query <strong>2</strong>: <code>res.json() / res.end()</code> and <code>connection.release()</code> both are async methods. Is it true?</p>
  
  <p>Query <strong>3</strong>: Even if the following code works perfectly, can I write <code>connection.release()</code> only once, i.e., just when <code>if else</code> statement ends? <strong>If yes, why doesn't <code>next()</code> works after res.end()` in Node.js?</strong></p>
  
  <pre><code>connection.query(query, [body.endDate, tripId], function (err, rows, fields) {
      if (err) {
          res.status(422).json(
              {
                  status: "error",
                  data: {error: {code: err.code, sqlMessage: err.sqlMessage}},
                  message: "Something didn't work."
              }
          );
          connection.release();
      } else {
          res.status(200).json(
              {
                  status: "success",
                  data: {affectedRows: rows.affectedRows},
                  message: "Trip ended."
              }
          );
          connection.release();
      }
  });
  </code></pre>