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

@nelts/process

v1.1.26

Published

nelts client inteface line tool

Downloads

20

Readme

@nelts/process

nelts安全进程辅助架构。

Usage

在项目中安装工具

npm i @nelts/process

开发模式下启动

ts-node node_modules/@nelts/cli/dist/runtime.ts --script={start file name}

生产环境下启动,建议使用PM2启动。

pm2 start node_modules/@nelts/cli/dist/runtime.js --name={name} -- --script={start file name}

Lifecycle

每个启动的进程对应一个script文件地址,它具有以下的生命周期:

  • componentWillCreate 进程启动前执行函数 此时 messager 不可用
  • componentDidCreated 进程启动完毕执行函数 此时 messager 可用
  • componentWillDestroy 进程结束前执行函数 此时 messager 可用
  • componentDidDestroyed 进程结束后执行函数 此时 messager 不可用
  • componentCatchError 统一错误捕获 参数为 error: Error
  • componentReceiveMessage 统一消息接受函数 (message, socket) => {}

script文件内容必须是一个返回的class对象

eg:

import { Component, Processer } from '@nelts/process';

export default class DemoComponent extends Component {
  constructor(processer: Processer, args: { [name:string]: any }) {
    super(processer, args);
  }
  async componentWillCreate() {}
  async componentDidCreated() {}
  async componentWillDestroy() {}
  async componentDidDestroyed() {}
  componentCatchError(err: Error) {}
  componentReceiveMessage(message:any, socket?:any) {}
}

它具有以下隐式方法

  • this.send(message:any, socket?:any) 发送消息
  • this.kill(pid?: number) 杀掉进程
  • this.createAgent(name: string, file: string, _args?: any) 创建子agent进程
  • this.createWorkerForker(file: string, _args?: any) 创建子worker进程

this.send(message:any, socket?:any)

  • message {object} 消息体 { to, event, data }
  • socket socket对象

发送消息

this.send({
  to: 'test',
  event: 'abc',
  data: {
    a: 1
  }
});

this.kill(pid?: number)

杀掉自身进程或者指定进程,或者全局结束所有进程

  • pid 进程ID。如果省略就是杀掉所有相关进程。
this.kill(process.pid);
this.kill(0); // 0 表示杀死全部

this.createAgent(name: string, file: string, _args?: any)

创建一个agent进程

  • name 进程名
  • file 进程执行文件地址
  • _args 额外参数 为json数据
import { Node } from '@nelts/process';
const agent: Node = await this.createAgent('test', 'test/file.js');
// agent 就是对应的Node进程节点

this.createWorkerForker(file: string, _args?: any)

创建一个worker进程forker。

  • file 进程执行文件地址
  • _args 额外参数 为json数据
const fork = this.createWorkerForker('test/worker.js');
await fork();
await fork();
await fork();
await fork();

License

MIT

Copyright (c) 2018-present, yunjie (Evio) shen