Vernacular: "API" vs "module"

I'm taking a NodeJS course right now, and it seems the instructor will refer to the "Event Emitter" API" We'd previously created a custom event emitter with
const eventEmitter = require('events'); const customEmitter = new EventEmitter();
and as far as I understood, the 'events' we are requiring above here is referred to as a NodeJS module, not an "API". Does it become an "API" when its instantiated or something (customEmitter)? Or is NodeJS "module" and "API" two interchangeable words for the same thing?
9 Replies
13eck
13eck2y ago
A short vocabulary lession: "API" stands for Application Programming Interface The events module exposes the events API. Each module has its own way of doing things (it's "interface") therefore each module exposes a specific API. API is, more-or-less, a catch-all term for how one interacts with a specific bit of code. In this instance, the event emitter module has a specific interface for how one programs an application using it. API (well, IPA, but that's more associated with bad beer lol).
thethingisback
lol okay, so the fact that we have to call new EventEmitter() in order to 'activate' it for lack of a better word.. that is what creates our "interface" for using it.. So then in my above code, "EventEmitter" would be the module, and "customEmitter" would be the actual interface/API?
13eck
13eck2y ago
Basically, yes
13eck
13eck2y ago
HTTP servers extend net.Server which is an instance of EventEmitter So even though you don't import/require the EventEmitter module the http server is a decendent of it Almost any Node class that waits for something to happen has EventEmitter somewhere in the prototype chain
thethingisback
the prototype chain, okay, so EventEmitter is pretty far up the chain then I'm assuming, but anyway, that makes sense
13eck
13eck2y ago
Yep! If you have some time I highly recommend reading the Node docs for the modules you're learning. You get a lot out of them (I find the Node docs to be one of the better-written I've read)
thethingisback
good idea, yep
Want results from more Discord servers?
Add your server