To understand that exports
syntax' you need to understand the node.js module structure a bit better:
Node.js (not NodeBB, it's just node.js) gives every module (every file that gets called somewhere using require(...)
, in this case from inside NodeBB core) a few (very few) global variables.
The relevant ones in this case are module
and exports
.
They in fact are the same from the beginning of module execution module.exports === exports
.
But if you want to export something else than a plain object (such as exports
) you can overwrite the exports
attribute of module
.
module.exports = "hello world";
// module.exports !== exports
// exports is now a meaningless object, not to be used anymore
What the two latter plugins do is to overwrite that module.exports
attribute with another object (it's just the decision the dev made) instead of giving the pre-defined module.exports
- that can also be referenced by exports
- some new attributes.
Just consider a var exports = module.exports = {};
being executed before module-initialization. exports
is a nice shortcut if you don't need to overwrite the container you want to export, but only it's attributes.
Documentation link: https://nodejs.org/api/globals.html
The other point regarding parameters for hooks can (mostly(?) at least since 0.8.0
I guess) be generalized to one parameter for action
hooks and two parameters for filter
or static
hooks.
action
: function (data) { ... }
- no callback since NodeBB doesn't wait for anything, actions are just to broadcast an event
filter
/static
: function (data, callback) { ... }
- callback to notify NodeBB back when you're done computing (by convention the callback needs to be called with callback(err, result)
where one of both needs to equal null
)
The data
is most likely an object you can check the values either within NodeBB core code or by simply console.log
ing them once.
@AccessDenied said:
@frissdiegurke Thank you for you well written response. That clears up a lot on why I'm confused - there just simply ISN'T documentation on anything. If I could ask, how did someone like yourself become familiar with the concepts behind NodeBB? Are they just intuitive or are they related to other forum/CMS style frameworks?
I've been into node.js (self-trained with help of brother) in first place - plain browser-side javascript mainly via userscripts and hobby pages even beforehand - and discovered NodeBB later on.
If you have some experience with any node.js application and know a few different conventions/styles (e.g. callback vs promise-based coding) you kind-of understand all node.js applications (as long they're not too bad written).
And since NodeBB is quite well-written from my point of view it isn't hard to get into it when you know the underlying language.
I've followed NodeBB since early days (not the very beginning, but 0.3.x
or so), so I've become familiar with their code-base and never had problems with reverse-engineering any feature I needed to know more about. Of cause I did ask the community a few times, mostly when I thought to have an idea of improvement or I felt like sth. was missing.
You're not a burden, I'm happy to help (besides some other reasons like improving my english knowledge). Otherwise I'd not be active within this community and would just keep writing my plugins within a dark room
. If I'd even bother to write the plugins then (since I mostly write them for this very same community...).