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

pluribus

v1.3.0

Published

Cluster manager

Downloads

40

Readme

Pluribus

Cluster manager for NodeJS. Pluribus allows you to run multiple workers, handles automatic respawns, graceful restarts and graceful shutdowns.

Pluribus accepts an option flag instructing it to watch for file changes in the directories you specify, during development.

Workers run with reduced privileges by default, and the number of workers is configurable (but defaults to the number of CPU cores).

Installation

Simple example


const pluribus = require("pluribus");

function worker() {
    console.log("I'm a worker");
}

function master() {
    console.log("I'm the master");
}

const options = {
    master: master,
    worker: worker,
    silent: false,
    privs: {user: "nobody", group: "nogroup"}
};

pluribus.execute("Example", options);

This example in use:

Killing and Restarting

Pluribus automatically spawns replacements for dead workers.

Watching for Changes and Manual Restart

If you send a --pluribus-watch flag to your application as a command line argument, it will watch for file changes in the directories specified in your configuration object. If you do not list any globs in your configuration, a default globs array will be used.

You can also watch for changes by including a watch: true property in your config object and running your application without the --pluribus-watch flag.

See the API documentation section of this readme for details of how to set up your configuration.

While watching for changes, you can manually restart your application by typing rs at the command line.

Specify a Custom Logger

If you provide a logging function in your configuration object, it will be used. For example, config.logger = require("winston").info.

API Documentation

Pluribus exports one method, called execute.

The execute method takes two arguments.

First is a string used for logging. Can be anything. We suggest the name of your app.

Second is a config object with the following format. All the values are optional, but the defaults may not suit you.

const config = {};

config.master = function () {};   // Function to execute as the master.
                                  //   Default: none defined

config.worker = function () {};   // Function to execute as the workers.
                                  //   Default: none defined
                                  //   (though optional, its kinda the whole point)

config.silent = true;             // If true pluribus will log nothing.
                                  //   Default: true

config.watch  = false;            // If true pluribus will watch for changes
                                  //   Default: false

config.workers = 2;               // How many workers to spawn.
                                  //   Default: number of CPUs

config.globs = [                  // Globs to watch.
    "/path/*",                    // Specify absolute paths, or pass each
    "/path/lib/*.js"              // element to path.resolve() (path = require("path")).
];                                // If path.resolve() is used, take care
                                  // to remove leading slashes from each relative path.
                                  // If watch is specified but globs is not,
                                  // it defaults to [ path.resolve("**/*.js"),
                                  // "!" + path.resolve(".", "node_modules", "**/*") ]

config.privs = {};                // Affects the privileges of workers.
config.privs.user  = "userName";  // The username to run workers as.
config.privs.group = "groupName"; // The group to run workers as.
                                  //    Default: nobody:nogroup

config.waitTimeout = 30000;       // The time (in ms) to wait for workers to drop
                                  // out before being forced to.
                                  //    Default: 30000 (30s)