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

@gaoding/ho-oh

v0.2.3

Published

nodejs process daemon plugin

Downloads

2

Readme

Ho-oh

https://bulbapedia.bulbagarden.net/wiki/Ho-Oh_(Pok%C3%A9mon)

deploy tool for Node.js project.

auto restart application worker process when process crash.

runnint hook support.

Installation

npm install @gaoding/ho-oh

Usage

ho-oh is a command line script tool for Node.js project.

Command

ho-oh

ho-oh
Commands:
  start [options]           启动
        -b, --basedir <d>   应用启动目录, 默认值 process.cwd()
        -T, --title <t>     应用运行时名称,会添加到启动的终端命令中,可通过 grep 查找到
        -d, --daemon        是否为进程守护模式运行,默认 false, 开启后应用启动后会退到后台运行
        -l, --logdir <d>    日志输出地址, 默认值 /home/log
        --ignore-stderr     忽略错误,会忽略启动时产生的 warn 或 error 日志,默认 false
        -w, --workers <n>   worker 进程数,默认值:1
        -t, --timeout <t>   应用启动超时,单位:秒,默认: 120
        --dispatch          应用启动入口文件,默认 `${process.cwd()}/dispatch.js`

  stop [options]            关闭
        -t, --title <t>     应用运行时名称, 不传会销毁所有 ho-oh 启动的服务进程

  help [command]            display help for command

Example

a Node.js Application include files like

- package.json
- index.js

package.json

{
    "name": "hooh-test",
    "version": "1.0.0",
    "description": "",
    "dependencies": {
        "ho-oh": "1.0.0",
        "koa": "^2.14.2"
    },
    "scripts": {
        "start": "ho-oh start --dispatch=index.js --workers=2",
        "stop": "ho-oh stop"
    },
    "author": ""
}

index.js

const koa = require('koa');

const app = new koa();

app.listen(2022, () => { console.log(`server started`) });

run npm start will got the command result

npm start

> [email protected] start
> ho-oh start --dispatch=index.js --workers=2

[2023-11-20 18:08:18] ho-oh start application without daemon
[2023-11-20 18:08:18] Worker: 60255 ready
[2023-11-20 18:08:18] Worker: 60256 ready
[2023-11-20 18:08:18] Master: 60254 ready
server started
server started

Messenger And Hooks

ho-oh support messenger and hooks.

messenger support to send message to other worker.

you can add hook function when dispatch before load and server before close;

Messenger

const koa = require('koa');
const { messenger } = require('ho-oh');

const app = new koa();

messenger.once('ready', () => {
    messenger.sendToWorker('i am: ' + process.pid);
});

messenger.on('message', message => {
    console.log(message);
});

app.listen(2022);

run app will send process pid to all workers

npm start

> [email protected] start
> ho-oh start --dispatch=index.js --workers=2

[2023-11-20 18:14:12] ho-oh start application without daemon
[2023-11-20 18:14:12] Worker: 60432 ready
[2023-11-20 18:14:12] Worker: 60431 ready
[2023-11-20 18:14:12] Master: 60430 ready
i am: 60432
i am: 60432
i am: 60431
i am: 60431

Hook

messenger has two hook function, beforeLoad and beforeClose.

const koa = require('koa');
const { messenger } = require('ho-oh');

const app = new koa();
app.status = 'runing';

messenger.addHook('beforeClose', async () => {
    app.status = 'closed';
    await new Promise(resolve => setTimeout(resolve, 5000));
});;

app.listen(2022);

if add beforeClose hook function, worker will run all hooks before close if you run npm stop.

Tips

服务偶尔需要添加一些自定义参数给到进程,这就需要透传自定义参数。

在 ho-oh 里,通过添加 --node-optiosn--${custom_key}=${value} 来添加自定义启动参数

ho-oh start --dispatch=index.js --workers=2 --node-options--max-uid=9999999