logoalt Hacker News

0x696C6961yesterday at 1:17 PM3 repliesview on HN

Is an `EventEmitter` a framework or a library?


Replies

andsoitisyesterday at 1:25 PM

> Is an `EventEmitter` a framework or a library?

It is best described as a pattern implementation (observer / pub-sub).

Example Node.js EventEmitter usage:

const EventEmitter = require('events');

emitter.on('data', handler);

emitter.emit('data', value);

-----------

You explicitly instantiate it. You explicitly register listeners. You explicitly emit events. It does nothing unless you call it. There's no lifecycle, no main loop, no required structure.

EventEmitter is not a framework because it does not define application structure. It doesn't own the program's control flow. It doesn't decide when your code runs (beyond callbacks you register). It does not enforce conventions or architecture.

People sometimes call it a framework incorrectly because of two sources of confusion:

1. Callback-based APIs feel like inversion of control. But this is partial IoC, not framework-level iOc.

2. It is often embedded inside frameworks. Examples: Express routes, React synthetic events, Electron internals.

ricardobeatyesterday at 1:33 PM

A library. It doesn’t define how you structure your application in any way.

baobunyesterday at 1:19 PM

Neither. It's an implementation of the interface in question.