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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@alarife/thread

v0.7.0

Published

Tool for the master builder's environment for the management of multiple processes.

Readme

alarife-thread - Tool for the master builder's environment for the management of multiple processes.

NPM Version License TypeScript

Tool for managing processes, subprocesses and communications between them in the Alarife framework.

📋 Table of Contents

🚀 Installation

npm install @alarife/thread --save-dev

📦 Basic Usage

Creating a thread (parent process)

import { Thread } from 'alarife-thread';

// Spawn a child process running a Node.js script
const thread = new Thread('./workers/my-task.js');

// Listen for events
thread.on('exit', (code: number) => {
  console.log(`Thread exited with code ${code}`);
});

thread.on('error', (err: Error) => {
  console.error('Thread error:', err);
});

// Terminate the thread when done
await thread.terminate();

Sending messages from a child process

import { threadContext } from 'alarife-thread';

// Send an event to the parent process
threadContext.send('task-completed', { result: 42 });

// Send an event without payload
threadContext.send('heartbeat');

Passing environment variables

import { Thread } from 'alarife-thread';

const thread = new Thread('./workers/my-task.js', {}, {
  API_URL: 'https://example.com',
  MAX_RETRIES: '3',
});

📖 Detailed API

Thread

Class that spawns and manages a child Node.js process. Extends EventEmitter.

Constructor

new Thread(path: string, options?: ThreadOptions, environment?: Record<string, any>)

| Parameter | Type | Description | |---------------|--------------------------|--------------------------------------------------------------------| | path | string | Absolute or relative path to the Node.js script to execute. | | options | ThreadOptions | Optional spawn options (extends SpawnOptionsWithoutStdio). | | environment | Record<string, any> | Optional environment variables passed to the child process. |

Throws Error if the path is empty or does not exist.

Methods

| Method | Returns | Description | |---------------|------------------|-------------------------------------------------------------------------| | terminate() | Promise<void> | Sends SIGTERM to the child process and resolves when it exits. |

Events

| Event | Callback signature | Description | |---------|--------------------------|------------------------------------------------------------------------| | exit | (code: number) => void | Emitted when the child process exits. Returns -1 if code is null. | | error | (err: Error) => void | Emitted when the child process encounters an error. |


threadContext

Singleton instance used inside a child process to communicate with the parent. Extends EventEmitter.

Methods

| Method | Returns | Description | |----------------------------------------------|---------|------------------------------------------------------------------| | send(event: string, payload?: unknown) | void | Sends an EventMessage to the parent process via IPC. |

Each call to send() generates a message with the following structure:

{
  kind: 'event',
  id: string,      // auto-generated UUID v4
  event: string,   // the event name
  payload: unknown // optional data
}

Message Types

type MessageKind = 'event' | 'rpc:request' | 'rpc:response';

| Interface | kind | Fields | |----------------|------------------|---------------------------------------------| | EventMessage | "event" | id, event, payload | | RpcRequest | "rpc:request" | id, method, args | | RpcResponse | "rpc:response" | id, result?, error? |

All messages conform to the union type ThreadMessage.

📄 License

This project is licensed under Apache-2.0. See the LICENSE file for details.


Built with ❤️ by Soria Garcia, Jose Eduardo

🌍 Product developed in Andalucia, España 🇪🇸

Part of the Alarife ecosystem