# @effectionx/node

> Node.js stream and event emitter adapters for Effection

Latest version **0.2.5** (published 2026-09-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install @effectionx/node
pnpm add @effectionx/node
yarn add @effectionx/node
bun add @effectionx/node
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.2.5 |
| Published | 2026-09-03 |
| First published | 2026-01-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 70.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 12 |
| Author | engineering@frontside.com |
| Maintainers | frontsidejack |
| Keywords | io, streams |

## Links

- npm: https://www.npmjs.com/package/@effectionx/node
- Repository: https://github.com/thefrontside/effectionx
- Homepage: https://github.com/thefrontside/effectionx#readme
- Issues: https://github.com/thefrontside/effectionx/issues
- npm.io page: https://npm.io/package/@effectionx/node

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 0.2.5 (latest) — 2026-09-03
- 0.2.4 — 2026-03-22
- 0.2.3 — 2026-03-08
- 0.2.2 — 2026-02-23
- 0.2.1 — 2026-02-12
- 0.2.0 — 2026-01-18

## README

# Node

Node.js-specific utilities for Effection programs. This package provides
adapters for working with Node.js streams and event emitters using structured
concurrency.

---

## Installation

```bash
npm install @effectionx/node
```

## Modules

This package provides two sub-modules:

- `@effectionx/node/stream` - Stream utilities for Node.js
- `@effectionx/node/events` - Event utilities for Node.js EventEmitters

You can also import everything from the main module:

```typescript
import { fromReadable, on, once } from "@effectionx/node";
```

## Stream Utilities

### fromReadable()

Convert a Node.js Readable stream to an Effection Stream.

```typescript
import fs from "node:fs";
import { each, main } from "effection";
import { fromReadable } from "@effectionx/node/stream";

await main(function* () {
  const fileStream = fs.createReadStream("./data.txt");

  for (const chunk of yield* each(fromReadable(fileStream))) {
    console.log(new TextDecoder().decode(chunk));
    yield* each.next();
  }
});
```

The returned stream emits `Uint8Array` chunks and automatically cleans up
event listeners when the stream is closed or the operation is shut down.

## Event Utilities

### on()

Create a Stream of events from any EventEmitter or EventTarget-like object.

This works with:
- Node.js EventEmitters (using `on`/`off`)
- DOM EventTargets (using `addEventListener`/`removeEventListener`)
- Web Worker's global `self` object

```typescript
import { each, main } from "effection";
import { on } from "@effectionx/node/events";

await main(function* () {
  // With Node.js EventEmitter
  for (const [chunk] of yield* each(on(stream, "data"))) {
    console.log("data:", chunk);
    yield* each.next();
  }

  // In a worker thread (EventTarget style)
  for (const [event] of yield* each(on(self, "message"))) {
    console.log("received:", event.data);
    yield* each.next();
  }
});
```

For EventEmitters, events are emitted as arrays of arguments.
For EventTargets, events are emitted as single-element arrays containing the
event object.

### once()

Create an Operation that yields the next event to be emitted by an EventEmitter
or EventTarget-like object.

```typescript
import { main } from "effection";
import { once } from "@effectionx/node/events";

await main(function* () {
  // Wait for a single message (EventTarget style)
  const [event] = yield* once(self, "message");
  console.log(event.data);

  // Wait for a single event (EventEmitter style)
  const [code] = yield* once(process, "exit");
  console.log("Process exited with code:", code);
});
```

## TypeScript Support

All exports include TypeScript type definitions. The event functions support
generic type parameters for type-safe event handling:

```typescript
import { once, on } from "@effectionx/node/events";

// Type the event arguments
const [code] = yield* once<[number]>(process, "exit");

// Type the stream events
for (const [data] of yield* each(on<[Buffer]>(stream, "data"))) {
  // data is typed as Buffer
  yield* each.next();
}
```

## Interfaces

The event utilities work with any object that implements these interfaces:

```typescript
// Node.js EventEmitter style
interface EventEmitterLike {
  on(event: string, listener: (...args: unknown[]) => void): void;
  off(event: string, listener: (...args: unknown[]) => void): void;
}

// DOM EventTarget style
interface EventTargetLike {
  addEventListener(event: string, listener: (event: unknown) => void): void;
  removeEventListener(event: string, listener: (event: unknown) => void): void;
}
```

---
_Source: https://npm.io/package/@effectionx/node · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
