title: How can I change this PhantomJS script to NodeJS for web scraping
body: <p>This is PhantomJS script that I use for scraping HTML DOM in web page. That use for waiting all DOM ready</p>
  
  <pre><code>//scrap_phantom.js
  var server = require("webserver").create();
  var page = require("webpage").create();
  var port = require('system').env.PORT || 3000;
  var url = "http://www.example.com";
  
  server.listen(port, function (request, response) {
      function onPageReady() {
          var htmlContent = page.evaluate(function () {  
              return document.documentElement.outerHTML;
          });
          response.write(htmlContent);
          response.close();
          phantom.exit();
      }
      page.open(url, function (status) {
          function checkReadyState() {
              setTimeout(function () {
                  var readyState = page.evaluate(function () {
                      return document.readyState;
                  });
                  if ("complete" === readyState) {
                      onPageReady();
                  } else {
                      checkReadyState();
                  }
              });
          }
          checkReadyState();
      });
  });
  </code></pre>
  
  <p>I'm testing it in cmd with "phantomjs scrap_phantom.js". The above code will work. Now, I change this code to NodeJS script like this:</p>
  
  <pre><code>//scrap_node.js
  var http = require("http");
  var phantom = require('phantom');
  var url = "http://www.example.com";
  
  http.createServer(function(request, response) { 
      function onPageReady() {
          var htmlContent = page.evaluate(function () {  
              return document.documentElement.outerHTML;
          });
          response.write(htmlContent);
          response.close();
          phantom.exit();
      }
  
  phantom.create(function (ph) {
      return ph.createPage(function (page) {
          page.open(url, function (status) {
              function checkReadyState() {
                  setTimeout(function () {
                      var readyState = page.evaluate(function () {
                          return document.readyState;
                      });
                      if ("complete" === readyState) {
                          onPageReady();
                      } else {
                          checkReadyState();
                      }
                  });
              }
              checkReadyState();
          });
      });
      }, {
          dnodeOpts: {weak: false}
      });
  }).listen(3000);
  </code></pre>
  
  <p>I'm testing it in cmd with "node scrap_node.js". This code will not work for me. It's loading for a long time and it doesn't return any errors. Why is it not working for me?</p>