Registry / serialization / event-emitter-promisify

event-emitter-promisify

JSON →
library1.1.0jsnpmunverified

event-emitter-promisify is a lightweight JavaScript and TypeScript utility library designed to convert Node.js `EventEmitter` instances into standard Promises. It enables developers to integrate asynchronous `async/await` syntax with traditional event-driven patterns, specifically by resolving a Promise when a success event (defaulting to 'end') is emitted, and rejecting it upon an 'error' event. The library provides a single, focused function, `promisifyEventEmitter`, which simplifies handling the lifecycle of event emitters in a Promise-based workflow. The current stable version is 1.1.0, released in February 2022. While functional and stable, the project exhibits an infrequent release cadence, with no major updates since its initial introduction. Its primary differentiation lies in offering a specialized solution for EventEmitters, distinguishing it from general-purpose promisification utilities like `util.promisify` that target Node.js-style callback functions.

npm install event-emitter-promisify
INSTALL
IMPORT
SIG · EVENT-EMITTER-PROM
E
event-emitter-promisify
serializationjavascriptv1.1.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

promisifyEventEmitter
✓ import { promisifyEventEmitter } from 'event-emitter-promisify'
✗ const promisifyEventEmitter = require('event-emitter-promisify')
This library is primarily designed for ESM environments, although CommonJS `require` might work with transpilation. TypeScript types are included.
promisifyEventEmitter (TypeScript Type)
✓ import type { PromisifyEventEmitter } from 'event-emitter-promisify'
✗ import { PromisifyEventEmitter } from 'event-emitter-promisify'
When importing only the type, use `import type` for better tree-shaking and explicit intent.

Demonstrates how to use `promisifyEventEmitter` with a simple Node.js Readable stream, collecting data and awaiting its completion.

import { promisifyEventEmitter } from 'event-emitter-promisify'; import { Readable } from 'stream'; async function processStream() { const stream = new Readable({ read() { this.push('some data'); this.push(null); // Signal end of stream } }); let receivedData = ''; const promise = promisifyEventEmitter( stream.on('data', (chunk) => { receivedData += chunk.toString(); }) ); try { await promise; console.log('Stream processed successfully. Received:', receivedData); } catch (error) { console.error('Stream encountered an error:', error.message); } } processStream();
Debug
Known issues
breakingThe package was renamed from `@jeswr/promisify-event-emitter` to `event-emitter-promisify` in version 1.1.0. Projects using the older scoped name must update their `package.json` and import paths.
fix
Update `package.json` to depend on `event-emitter-promisify` and change all import statements from `@jeswr/promisify-event-emitter` to `event-emitter-promisify`.
affects: >=1.1.0
gotchaBy default, the promise resolves when the `end` event is emitted. If your `EventEmitter` never emits an `end` event, the promise will never resolve unless an `error` event is emitted or a custom success event is configured.
fix
Ensure your `EventEmitter` pipeline reliably emits an `end` event upon completion, or provide a second argument to `promisifyEventEmitter` to specify a custom event that signifies success and a return value.
affects: >=1.0.0
gotchaThe promise will only reject if the `error` event is emitted by the `EventEmitter`. If an underlying asynchronous operation fails without emitting an `error` event, the promise may hang indefinitely.
fix
Implement robust error handling within your `EventEmitter` producer to ensure that any failure condition results in an `error` event being emitted. Alternatively, introduce a timeout mechanism for the promise if hanging is a concern.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: stream.on is not a function
You are attempting to use `promisifyEventEmitter` with an object that does not expose an `.on()` method, meaning it's not a valid `EventEmitter` instance.
fix
Ensure the variable passed to `promisifyEventEmitter` is an instance of `EventEmitter` or an object that implements the `on` method (e.g., a `Readable` stream, `net.Socket`, etc.).
Promise never resolves (application hangs)
The `EventEmitter` passed to `promisifyEventEmitter` (or its underlying mechanism) is not emitting the 'end' event (or a custom configured success event) and is also not emitting an 'error' event.
fix
Review the logic of your `EventEmitter` producer to verify that it eventually emits a 'end' event (or your specified custom success event) when its operation completes, or an 'error' event if a failure occurs. Debug the EventEmitter's event flow.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
event-emitter-promisify — npm install event-emitter-promisify · libregistry