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

ghost-town

v3.0.0

Published

Simple queued & clustered PhantomJS processing.

Downloads

26

Readme

license version dependencies
Simple queued & clustered PhantomJS processing. https://www.npmjs.com/package/ghost-town

Now with 100% creepier dependencies! Check out Ghost Town 3's breaking changes in CHANGELOG.md.


Need highly scalable PhantomJS processing? Ghost Town makes it frighteningly easy! For example, on-demand page rendering, dispatched through Thrift:

var town = require("ghost-town")();

if (town.isMaster) {
    thrift.createServer(Renderer, {
        render: function (html, width, height, next) {
            town.queue({
                html: html,
                width: width,
                height: height
            }, function (err, data) {
                next(err, !err && new Buffer(data, "base64"));
            });
        }
    }).listen(1337);
} else {
    town.on("queue", function (page, data, next) {
        // sequential page setup
        // page.property("viewportSize", ...)
        // page.property("customHeaders", ...)
        // page.property("onLoadFinished", ...)
        // page.property("content", ...)
        
        page.renderBase64("jpeg").then(function (res) {
            next(null, res);
        }).catch(next);
    });
}

Ghost Town uses Node's Cluster API, so the master and worker share their code. On the master side, queue items and handle their results. On the worker side, process items and return their results.

Requires Node 4+ and PhantomJS 2.1+.


town(options)

  • phantomBinary: String path to the PhantomJS executable. Default: Automatic via $PATH.
  • phantomFlags: Object of strings to use for the PhantomJS options. Default: {}.
  • workerCount: Number of workers to maintain. One or two per CPU is recommended. Default: 4.
  • workerDeath: Number of items to process before restarting a worker. Default: 25.
  • workerShift: Number of milliseconds to wait before restarting a worker. Default: -1 (forever).
  • pageCount: Number of pages to process at a time. If your processing is mostly asynchronous (vs. e.g. render blocked), increasing this is recommended. Default: 1.
  • pageDeath: Number of milliseconds to wait before before requeuing an item. If your processing is time-sensitive, decreasing this is recommended. Default: 30000.
  • pageTries: Number of times to retry items that have timed out. If your processing could fail forever, configuring this is recommended. Default: -1 (unlimited).

Starts Ghost Town and returns a Master or a Worker instance exposing the following.

  • Master#isRunning is set by Master#start() and Master#stop().
  • Master#isMaster and Worker#isMaster can be used to separate master- and worker-specific code.
  • Worker#phantom is the PhantomJS wrapper object provided by phantom.

Master#start() and Master#stop()
Starts or stops processing. These spawn or kill workers and PhantomJS processes, so they're useful for managing resource usage or gracefully shutting down Node.

Master#queue(data, [asap], next)
Queue an item for processing by a worker. data is passed to Worker!queue(), and next(err, data) is called when complete. Optionally pass true to asap to prepend to the queue.

Worker!queue(page, data, next)
Fired when a worker receives an item to process. page is the PhantomJS page, data is what was passed to Master#queue(), and next(err, data) passes it back.


© 2016 Buzzvil, shared under the MIT license.