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
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?const eventEmitter = require('events');
const customEmitter = new EventEmitter();
9 Replies
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).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?Basically, yes
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 chainthe prototype chain, okay, so EventEmitter is pretty far up the chain then
I'm assuming, but anyway, that makes sense
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)
good idea, yep