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

node-clusterprocess

v2.1.0

Published

Wrapper around Node.js' cluster module for zero-downtime deployment of Node.js Apps. By entrecode.

Downloads

290

Readme

node-clusterprocess

Wrapper around Node.js' cluster module for zero-downtime deployment of Node.js Apps. By entrecode.

npm version

What is this and what does it do?

This module supports node's clustering to utilize multi-core systems. It can be used by basically any Node.js Application to enable zero-downtime deployments.

Usage

server.js:

require('node-clusterprocess').run('app.js', 'myApp');

This should be a separate Node.js script, and it should be specified as main executable in your project's package.json. When you start your Application, you will call node server.js from now on instead of node app.js.

Zero-Downtime Reloading

You can trigger zero-downtime reloads of your application by sending HUP:

kill -hup <pid>

… where <pid> should be the PID of the cluster process. Alternatively, you can use

pkill -hup -x myApp_cp

… where myApp_cp is the title of the cluster process (consisting of your provided processName and the suffix _cp).

API

ClusterProcess offers the following methods:

run(executable[, processName])

executable is the name of your main script that should be executed as worker. As path the directory of the requiring module is assumed automatically (path.dirname(module.parent.filename)).

processName is optional. If omitted, the process name is taken from your package.json title property. It will be used as process title. It should not be too long according to the Node.js Documentation. Note that the master process will be called processName_cp and the worker processes should be named processName-w by your code.

setLogger(loggingInstance)

ClusterProcess uses console logging by default for nicer logging to stdout/console (with timestamps and colors). You can overwrite this with another (e.g. global) logging instance using this method. The logging class is required to provide methods log, info, warn and error.

handleSignals(cleanFunc = noop)

ClusterProcess can handle signals SIGHUP, SIGINT, and SIGTERM. An cleanFunc must be provided and ClusterProcess will call this function on receiving signals.

ClusterProcess' methods are chainable, so you can set a logger, call handleSignals(), and call run() in one line.

Changelog

2.1.0

  • support for esm modules

2.0.0

  • removed timeout and exit from handleSignals, parent modul must exit in their cleanup callback

1.1.0

  • changed stop behavior when receiving SIGTERM, will send SIGINT to worker, after 10 seconds will send SIGTERM

1.0.2

  • fix handling of term signal

1.0.1

  • use logger instance instead of console logging

1.0.0

  • initial public release of node-clusterprocess