npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ectoplasm

v0.3.2

Published

Alternative bridge between NodeJS and PhantomJS

Downloads

6

Readme

ECTOPLASM

This is yet another bridge between NodeJS and PhantomJS.

Build Status

Why is this needed?

node-phantom is all nice and good but the callback system does get a bit clunky, e.g. if you're setting a bunch of properties at the same time. Plus, it lacks the flexibility you'd get from using PhantomJS direct.

Using PhantomJS on its own is all good and nice but calling exec all the time and dealing with stdout and stderr is a faff, plus there's a noticeable delay every time you fire up PhantomJS. This is annoying if you need to run your scripts multiple times in a row.

Ectoplasm tries to hit a happy middle, using node-phantom's sockets method to manage a continuous Phantom process but allowing you to run your own scripts.

Installing

npm install --save ectoplasm

API

initialise(scripts, [options], callback) or initialize(scripts, [options], callback)

Pass your script names as an object, for instance:

var ecto = require("ectoplasm"),
  scripts = {
    doThings: "/absolute/path/to/doThings.js"
  };

ecto.initialise(scripts, function (err) {
  // err is populated if it can't find the scripts
});

options is an object. The options supported for the moment are phantomPath and debug.

phantomPath

Set this if your PhantomJS binary is not in your $PATH:

For instance, if you're using the excellent phantomjs module, you'd do:

var ecto = require("ectoplasm"),
  phantomjs = require("phantomjs"),
  scripts = {
    doThings: "/absolute/path/to/doThings.js"
  };

ecto.initialise(scripts, { phantomPath: phantomjs.path }, function (err) {
  // ...
});

debug

Set this to true for detailed debugging information. It also enables tracing of all console messages from the Phantom process.

cleanup(callback)

Kills the Phantom process and stops the internal servers.

run(scriptName, [args ...], callback)

Runs a script that you've previously loaded, for example:

var ecto = require("ectoplasm"),
  scripts = {
    "doThings": "/absolute/path/to/doThings.js"
  };

ecto.initialise(scripts, function (err) {
  ecto.run("doThings", { foo: "bar" }, function (err, result) {
    // things have been done
  });
});

args is optional, and you can have as many of them as you want (or none at all) between your script name and callback.

NOTE: args is serialized to JSON as it's passed to the Phantom side. Be wary of trying to pass values that can't be serialized. For example:

var args = {
  foo: "bar",
  baz: function () { return "Hello!"; }
};

// the frontend will only receive { foo: "bar" }

Scripts

Your script must expose a single method called run, for example:

// inside doThings.js
exports.run = function (args, callback) {
  if (args.foo === "bar") {
    callback(null, "yay!");
  } else {
    callback("error!");
  }
};

You can pass any number of arguments back in your script.

Two scripts are already made available:

  • ping simply returns your args back to you - in case you want to test things.
  • addScripts adds scripts at runtime, much like initialise:
ecto.run("addScripts", {
  doSomethingElse: "/absolute/path/to/doSomethingElse.js"
}, function (err) {
  // you can now run doSomethingElse, too
});

License

MIT