title: What does response.on mean? Node.js
body: <p>I am having trouble with a Node.js http request. (A bigger question I will ask about later if I can't figure it out).</p>
  
  <p>I have code that I modified from and an example and I don't understand what the response.on means. As read more about http in Node.js (<a href="https://nodejs.org/en/docs/guides/anatomy-of-an-http-transaction/" rel="nofollow">Anatomy of an HTTP Transaction</a>) I don't see people using examples with 'response.on'. I think I know but I want to clarify. Oh I am using Express.js too.</p>
  
  <p>Thanks</p>
  
  <p>Below is the code I am using to try and call the BART api I need a response from.</p>
  
  <pre><code>...
  // Real Time Departure from a given station
  router.route('/departTimeStation')
  .get(function(req, res) {
      vCmd = 'etd';
      vOrig = req.query.vOriginStation;
      vDir = 'n'; // [NOTE] - 'n' or 's', north or south, OPTIONAL
      vPlat = 1; // [NOTE] - 1 to 4, number of platform, OPTIONAL
  
      var xoptions = {
          host: 'api.bart.gov',
          path: '/api/etd.aspx?cmd=' + vCmd + '&amp;orig=' + vOrig + '&amp;key=' + config.bart.client
      };
  
      var xcallback = function(response) {
  
          response.on('data', function(chunk) {
              vParsed += chunk;
          });
  
          response.on('end', function() {
              parseString(vParsed, function(err, result) {
                  vShow = JSON.stringify(result);
                  vTemp = result;
              });
          });
      };
      http.request(xoptions, xcallback).end();
      return res.send (vTemp)
  });
  ...
  </code></pre>