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 🙏

© 2025 – Pkg Stats / Ryan Hefner

pm2-babysitter

v0.0.1

Published

Oversight to PM2 which will reboot servers based on a ruleset

Readme

PM2-Babysitter

Oversight to PM2 which will reboot servers based on a ruleset.

In its simplest form this module will ensure that primary apps will be rebooted when they stop responding.

In a more complex form: an advanced ruleset can be defined to restart a PM2 app structure if something goes horribly wrong.

PM2-Babysitter can be used in three separate ways:

  1. Via an API
  2. Directly via the Command Line
  3. Within PM2 itself (Recommended)

API Example

var babysitter = require('pm2-babysitter');

// Just watch this app and reboot it if port 80 stops responding. This invokation is actually shorthand for the below
babysitter.add('my-pm2-app', 'http://localhost');


// Full version of the above
babysitter.add('my-pm2-app', [
	babysitter.rules.get('http://localhost'),
]);


// More detailed version of the above which also checks for a string (or a RegExp if given one)
babysitter.add('my-pm2-app', [
	babysitter.rules.get('http://localhost', 'Hello World'),
]);


// Expect a JSON response from a given URL and validate that it has 'foo.bar.baz'
babysitter.add('my-pm2-app', [
	babysitter.rules.get('http://localhost', function(cb, res) {
		// Perform JSON validation or any other kind of response verification here
		if (_.has(res.body, 'foo.bar.baz')) return cb('Invalid response');
		cb();
	}),
]);

CLI Example

The below example runs pm2-babysitter directly from the command line. It is recommended that you use the PM2 method (below) instead as that can be monitored by PM2 itself.

// Run pm2-babysitter to monitor to the app 'my-pm2-app' and restart it if 'http://localhost' stops responding
pm2-babysitter --app my-pm2-app --url http://localhost

PM2 Example

The pm2-babysitter is designed to operate as a process within PM2 itself. To do this use it in a similar manor to the CLI Example.

// Run pm2-babysitter as a PM2 process, monitoring 'my-pm2-app' and restart if 'http://localhost' stops responding
pm2 start `which pm2-babysitter` -- --app my-pm2-app --url http://localhost

As an example you can use the following to set up a both a test web server and a pm2-babysitter process. The below commands assume you are already in the pm2-babysitter NPM directory

// Start a dummy web server
pm2 start test/servers/web.js --name web

// Start the pm2-babysitter process (in very-very verbose mode)
pm2 start cli.js -- --app web --url http://localhost:8080 -vvv