title: Using nodeJS and phantomJS to return network requests and responses, only working in console
body: <p>I'm trying to replicate the phantomJS <a href="https://github.com/ariya/phantomjs/blob/master/examples/netlog.js" rel="nofollow">netlog.js</a> functionality, only in nodeJS. I'm using the <a href="https://github.com/sgentle/phantomjs-node" rel="nofollow">phantomjs-node module</a> as a bridge. </p>
  
  <p>Normally, this would be run headlessly in the command line using <code>phantomjs netlog.js http://www.google.com/</code>. It would return a lot of json containing all network requests and responses.</p>
  
  <p>What I'm doing here is trying to run the code from <code>netlog.js</code> inside of a page created using the <code>phantomjs-node</code> module (ignoring the line <code>var page = require('webpage').create()</code> from <code>netlog.js</code>.</p>
  
  <p>While the code doesn't break, I'm not getting the return of the json. What's wrong here? Do I need to somehow pipe the page request? </p>
  
  <p>In <code>app.js</code>: </p>
  
  <pre><code>var phantom = require('phantom');
  
  siteUrl = "http://www.google.com/"
  phantom.create(function (ph) {
      ph.createPage(function (page) {
          var system = require('system'),
          address;
          page.open(siteUrl, function (status) {
          // console.log("opened " + siteUrl +"\n",status+"\n");
  
              page.evaluate(function () { 
                  if (system.args.length === 1) {
                      console.log('Usage: netlog.js &lt;some URL&gt;');
                      phantom.exit(1);
                  } else {
                  console.log(system.args[1])
                      address = system.args[1];
  
                      page.onResourceRequested = function (req) {
                          console.log('requested: ' + JSON.stringify(req, undefined, 4));
                      };
  
                      page.onResourceReceived = function (res) {
                          console.log('received: ' + JSON.stringify(res, undefined, 4));
                      };
  
                      page.open(address, function (status) {
                          if (status !== 'success') {
                              console.log('FAIL to load the address');
                          }
                          phantom.exit();
                      });
                  }
  
              }, function finished(result) {
  
                  ph.exit();            
              },thirdLayerLinks);
  
          });
      });
  }, {
  dnodeOpts: {
      weak: false
  }
  });
  </code></pre>