Phapper

Build Status   Dependancy Status   NPM Version  

Simple PhantomJS Script wrapper for Node.js, which parsed JSON output from the passed PhantomJS script (if possible).

Links

Node.js Version

Tested on the following node versions (via Travis-ci.org):

  • 0.8
  • 0.10

Install

$ npm install phapper

Note: On CentOS 6, I had to install the following packages: - sudo yum install freetype fontconfig

Additional Installation Notes

You can specify different versions of PhantomJS using npm config:

$ npm config set phantomjs_version

You will have to reinstall phapper if you change this option after initially installing it.

I've added limited Windows support, in that you'll have to install PhantomJS yourself and then specify the path in your code:

var Phapper = require('phapper');
Phapper.prototype.bin = 'c:\path\to\phantomjs.exe';

It's important to note that I haven't tested this on Windows (and don't really have an easy way to), so feedback and/or pull requests are welcome.

Usage

var Phapper = require('phapper');
var phap = new Phapper("/path/to/phantom/script.js",
                        [ "--arg1", "val1", "--arg2", "arg3" ]);
// Phapper also takes an Object as a third argument which can be
// anything you might pass to `child_process.exec`. E.g. `env`,
// `cwd`, etc. When using runSync, only `cwd` is supported.


// Note: runSync is pretty inefficent due to execSync.exec.
console.log("Run Sync");
var results = phap.runSync();
// => results
// {
//    parsed: { parsed json from stdout || undefined },
//    output: "stdout string\nstderr string"
// }
if (results.parsed) {
    console.log("result object:\n%j", results.parsed);
} else {
    console.log(results.output);
}

console.log("Run Async");
phap.run( function (result, resultObj) {
    // => result
    // { parsed json from stdout || undefined }
    // => resultObj
    // {
    //    stdout: "stdout string",
    //    stderr: "stderr string"
    //    error:  "error string"
    // }
    if (result) {
        console.log("Results:\n%j", result);
    }
    console.log("Raw Results:");
    console.log(resultObj.stdout);
    console.log(resultObj.stderr);
    if (resultObj.error) {
        console.error(resultObj.error);
    }
});

Articles on Phapper

YSlow.js: Release 0.3.1

Links: readme | package | source | tests

0.3.2

Previous Version

  • 0.3.1
  • 0.3.0
    • Fixing error handling in run. Now passes both error and results to callback. See README examples for details. This update is not backwards compatabile with previous releases.
  • 0.2.1
    • Removing unused dependainces.
  • 0.2.0
    • Top down refactor using updated Phapper.
    • Includes better pathing support for finding included yslow.js.
    • Downloads and install yslow.js if it can't be found, which should never happen.
    • Adding limited support for Windows.
  • 0.1.2
    • Fixing critical issue in NODE_PATH search when working with global installations.
  • 0.1.1
    • Refactored to use Phapper, way cleaner and less code.
    • Refactored tests for change to Phapper.
    • Refactored stubs..
    • Adding functional tests.
  • 0.0.1
    • Initial release.

Phapper.js: Release 0.1.9

Links: readme | package | source | tests

0.1.9

  • Fixing a minor bug with the install script.

Previous Versions

  • 0.1.8
    • Updating PhantomJS version to 1.9.7.
  • 0.1.6
    • Replacing exec-sync with execSync for easier Mac installation.
  • 0.1.5
    • Removing unused dependancies.
  • 0.1.4
    • Fixing small issue with passed in arguments on init.
    • Added ability to pass exec object, see readme examples.
    • Cleaned up tests, added more.
    • Cleaned up make test / npm test.
    • Allowing for passing of cwd to sync function.
  • 0.1.3
    • Adding windows handling and phantomjs version overide.
    • Updating readme.
  • 0.1.2
    • Adding phantomjs install.
    • Adding better phantomjs path support.
  • 0.1.1
    • Refactored to not require JSON stdout parse.
    • Refactored run and runSync return values, see readme.
  • 0.0.1
    • Initial release.

Benchmarking with YSlow.js on Node.js

In my last post on this topic (Benchmarking with HTTPerf.js and NodeUnit) I covered benchmarking application render times from the server to first byte. In this post, I'm going cover basic client benchmarking using YSlow and PhantomJS via YSlow.js on Node.js.

Continue reading