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

express-cluster

v0.0.5

Published

Simple drop-in for express apps to spawn multiple processes

Downloads

17,696

Readme

express-cluster

Run an express server on multiple processes. This is meant to be dropped in directly to your main entry point without having to setup a separate script that manages workers.

This works with any EventListener that emits the "close" event and has a close() method. If it's a server object (e.g. an express app, net.Server or http.Server, ensure that you've invoked listen before returning it).

By default the module will spawn os.cpus().length workers. You should configure this parameter for your workloads. You should pick the right number for your server based on testing.

Synopsis

var express = require('express');
var cluster = require('express-cluster');

cluster(function(worker) {
    var app = express();
    app.get('/', function(req, res) {
        res.send('hello from worker #' + worker.id);
    });
    return app.listen(0xbeef);
}, {count: 5})

API

express-cluster exports itself as a function that accepts config and workerFunctions as arguments. These can be provided in either order: cluster(config, workerFunction) or cluster(workerFunction, config).

Once node executes cluster() the current process will be forked the specified number of times. You should guard any code that should only be run in the master behind a check of process.env.NODE_UNIQUE_ID or a call to node's cluster.isMaster

workerFunction

This function is passed a worker object. See the node documentation for Worker for details.

config

This object should contain zero or more of these keys. Any other key/values are ignored.

{
    count: 5,       // number of workers: defaults to os.cpus().length
    respawn: true,  // respawn process on exit: defaults to true
    verbose: false, // log what happens to console: defaults to false

    // Attach the given function to each spawned worker. The function will
    // be bound to the worker that sent the message so you can setup a two
    // way message bus if you please. See examples/messaging.js for an
    // example.
    workerListener: function(){},

    // When in verbose mode, use a following writable stream (supports
    // the write function) instead of the default console
    outputStream: writableStream
}