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

nounou

v1.2.1

Published

Node.js process daemon

Downloads

13,672

Readme

nounou(保姆)

Node.js process deamon.

非Cluster模式的进程守护

cluster的fork形式仅能对单一进程使用。nounou适合其他情况,比如守护定时任务。

注意:nounou仅负责重启,不负责调度,不负责负载均衡。

Usage

编程式使用:

const nounou = require('nounou');
const timerPath = '/path/to/timer.js';

// 任务进程
nounou(timerPath).on('fork', (worker) => {
  console.log('[%s] [%d] new task worker start', Date(), worker.pid);
}).on('disconnect', (worker) => {
  console.error('[%s] [%s] task worker: %s disconnect.',
    Date(), process.pid, worker.pid);
}).on('unexpectedExit', (worker, code, signal) => {
  var err = new Error(util.format('task worker %s died (code: %s, signal: %s)',
    worker.pid, code, signal));
  err.name = 'WorkerDiedError';
  console.error('[%s] [%s] worker exit: %s', Date(), process.pid, err.stack);
}).on('reachReforkLimit', () => {
  console.error('Too much refork!!!!!!');
});

命令式使用:

$ nounou /path/to/timer.js
# multi workers
$ nounou /path/to/timer.js 2

正常退出

如果子进程在运行一段时间后需要退出,之后无需重启。需要通过如下方式进行退出:

process.send({type: 'suicide'});
process.exit(0);

该行为会触发expectedExit事件,标志退出符合预期,无需重启。

Events

  • exit。退出事件。
  • expectedExit。预期的退出事件。
  • unexpectedExit。非预期的退出事件。
  • disconnect。IPC通道断开的事件。
  • reachReforkLimit。单位时间内重启次数达到上限。该事件后,进程不会再次重启。

注意事项

通常kill掉nounou主进程,它守护的子进程并不会随之而退出。如需子进程跟随父进程退出,需要以下代码:

// exiting with parent process
process.on('disconnect', () => {
  console.log('exiting with parent process');
  process.exit(0);
});

License

The MIT license