Demitter: Distributed Event Emitting for Node.js Goes Zero-Config
Share this article
For Node.js developers building distributed systems, coordinating events across processes has traditionally required complex message brokers or heavyweight solutions. Enter Demitter, a new open-source library that brings Node.js' familiar event emitter pattern to distributed environments with near-zero configuration.
The Event Distribution Problem
Node.js' native EventEmitter is beloved for its simplicity in single-process applications. But scaling beyond one process introduces significant complexity:
// Traditional single-process events
const EventEmitter = require('events');
const emitter = new EventEmitter();
emitter.on('update', data => console.log(data));
Demitter solves this by extending the popular emittery API across processes using ZeroMQ's robust pub/sub pattern. The result? Distributed events that feel like local ones.
Zero-Config Architecture
Demitter's power lies in its two-component architecture:
- DistributedEmitter: API-compatible replacement for emittery
- Message Forwarder: Lightweight broker (deploy embedded or standalone)
// 1. Start forwarder (broker)
import { createForwarder } from "demitter";
const forwarder = await createForwarder();
// 2. Create emitters in separate processes
const emitterA = await createDistributedEmitter();
const emitterB = await createDistributedEmitter();
// 3. Communicate cross-process
emitterA.on('alert', data => console.log(data));
emitterB.emit('alert', { critical: true });
The forwarder uses ZeroMQ's XSUB/XPUB proxy pattern, handling message routing while Demitter manages serialization and delivery guarantees. Developers get:
- 🚀 Automatic reconnection
- đź”’ Binary-efficient serialization
- 🛡️
distributed:errorevent for network failures - 📦 12KB overhead (gzipped)
Real-World Applications
Live auction demo showing cross-process bidding (Source: Demitter GitHub)
Demitter shines in scenarios requiring cross-process coordination:
- Microservices: Replace HTTP polling with event-driven communication
- Multi-process Node: Coordinate worker threads or child processes
- Real-Time Systems: Live auctions (as demonstrated in their interactive demo)
- IoT Networks: Synchronize device states across edge nodes
Deployment Flexibility
Run the forwarder as:
- Embedded process within your application
- Standalone service via CLI:
npx demitter-forwarder
# Or with custom ports
XSUB_PORT=6000 XPUB_PORT=6001 demitter-forwarder
- Docker container for cloud-native deployments
Why This Matters
Demitter eliminates one of Node.js' most persistent distributed systems hurdles. By preserving emittery's API—including TypeScript support and familiar methods like .emit(), .on(), and .once()—it provides immediate productivity gains. The library's deliberate constraints (no queues or persistence) reveal its focused philosophy: do one thing well.
As event-driven architectures dominate cloud-native development, tools like Demitter that bridge local development simplicity with distributed systems power will become increasingly vital. For teams already using emittery, adopting distributed events may now be just an npm install away.
Source: Demitter GitHub Repository