title: Nodejs Promise "res.end is not a function" error
body: <p>I'm refactoring my code to remove a "callback hell" using Promises, but encountered an error that I cannot pass. My code receives list of IDs and processes them making few database calls, that is why I had this "callback hell".
  Everything worked fine until Promises. The <code>res</code> is equal <code>0</code> when I had to respond back to the client.</p>
  
  <pre><code>  function processVMDelete(returnedVMIDs){
      return new Promise((resolve, reject) =&gt; {
  
          var mariasqlClient = dbConnection();
          mariasqlClient.query( sqlUpdateDELETE_STATE_ByVMID, [ 
            'DELETE', 
            returnedVMIDs
          ], function(err, rows) {
            if (err){
              reject(err);
            }
            console.log('finish update');
  // dont' need to return anything here
            resolve(0);
          });
          mariasqlClient.end();
      });
    }
  
    function getListExpVM(){
      return new Promise((resolve, reject) =&gt; {
  
        var vmList = [];
        var mariasqlClient = dbConnection();
        mariasqlClient.query( sqlSearch_ByUSERNAMEAndSTATE, [ 
          requesterUsername, 
          'ACTIVE'
        ], function(err, rows) {
          if (err){
            reject(err);
          }
            vmList = filterExpiredVMs(rows);
  
            var response = {
              status : 200,
              success : 'Successfull',
              data : vmList,
              requester: requesterUsername
            };
            resolve(response);
        }); 
        mariasqlClient.end();
      });
    }
  
  
  
  router.post('/processVMs', function(req, res) {
      var returnedVMIDs = JSON.parse(req.body.data);
  
      processVMDelete(returnedVMIDs)
        .then(res =&gt; {
          console.log('done');
  
          // check if there is more available for the user:
          getListExpVM()
            .then(response =&gt; {
              console.log('sending back list of VMs');
  
  //===&gt;&gt;&gt; ERROR HERE: res.end is not a function
              res.end(JSON.stringify(response));
  
            })
            .catch(err =&gt; {
              console.log('error', err.message);
              logger.error("Error getting expired VMs: " + err.message);
  
  //===&gt;&gt;&gt; ERROR HERE: res.send is not a function
              res.status(500).send({error: err.message})
            });
        })
        .catch(err =&gt; {
          console.log('error', err.message);
          logger.error("Error processing VMs: " + err.message);
  //===&gt;&gt;&gt; ERROR HERE: res.send is not a function
          res.status(500).send({error: err.message})
        });
  });
  </code></pre>