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

revive

v1.1.8

Published

Process Management Tool | Auto Restarts | Advanced Events | And More

Downloads

36

Readme

Process Management Tool | Auto Restarts | Advanced Events | And More Warning 1.1.1 Breaking API Changes

Revive

A process management tool. Events, status, cluster, and automatic restarts.

Install

npm install revive

Example

const Revive = require('revive');

const options = {
	name: 'test',

	cmd: process.execPath,

	arg: ['app.js'],
	env: { PORT: 8000 },
	cwd: '/home/user/code/node/app/.',

	cluster: true,
	instances: 2,

	stdout: '/logs/stdout.log',
	stderr: '/logs/stderr.log',

	sleepTime: 1000,
	crashTime: 6 * 1000,
	maxCrashCount: 1000
};

const monitor = Revive(options);

monitor.on('start', function () {
	console.log(monitor.toJSON());
});

monitor.start();

Options

  • name: String Defaults to null the name of the process.

  • arg: Array, String Defaults to null arguments or node script.

  • cwd: String Defaults to process.cwd() the current working directory.

  • cmd: String Defaults to process.execPath the systems absolute executable/node path.

  • cluster: Boolean Defaults to false.

  • instances: Number Defaults to Os.cpus().length if cluster is set to true

  • stdout: String Defaults to 'pipe' otherwise a file path. If a path is provided than this event will not fire.

  • stderr: String Defaults to 'pipe' otherwise a file path. If a path is provided than this event will not fire.

  • sleepTime: Array, Number Defaults to 1000 in milliseconds to sleep between start after a crash.

  • crashTime: Number Defaults to 60000ms. The time until the maxCrashCount resets. So if 1000 crashes happen in 60s then the process will exit.

  • maxCrashCount: Number Defaults to 1000 crashes. A crash is triggered and the process exited at nth + 1.

  • env: {} Environment variables for the process.

  • data: {} A custom object for you.

API

  • monitor.start() Starts the monitor

  • monitor.stop() Stops the monitor (kills the process if its running with SIGKILL).

  • monitor.restart() Restarts the monitor by stopping then starting (process must be started).

  • monitor.toJSON() Creates a stringyifiable object. The object returns stats and data about the process.

Cluster Events

  • monitor.on('status', callback)

  • monitor.on('start', callback) Starts the process. Warning async so process may not be available immediately.

  • monitor.on('stop', callback) The process and it's tree is sent a SIGTERM signal. If the process does not terminate after ten seconds then the process is sent a SIGKILL signal.

  • monitor.on('restart', callback) Same as stopping then starting or vice versa.

  • monitor.on('stdout', callback) Emits an stdout. Only available if no Options.stdout is pipe.

    • Stdout Parameter the stdout message.
  • monitor.on('stderr', callback) Emits an stderr. Only available if no Options.stderr is pipe.

    • Stderr Parameter the stderr message.
  • monitor.on('error', callback) Emits when the process could not spawn, kill, or a message failed.

    • Error Parameter the error message.
  • monitor.on('exit', callback) The process has exited.

    • Code The numeric exit code
    • Signal The string signal

Instance Events

  • monitor.on('reload', callback) Zero downtime restart if cluster is set to true and instances is greater than one.

  • monitor.on('sleep', callback) Triggered when process crashes and enters sleep.

  • monitor.on('crash', callback) Triggered when the process crashes.

Issues

Immediate start then stop execution does not send the signals. This could be a problem with node.js.