I'm a NOOB to NodeJs and trying to understand the difference and pros and cons to a couple of patterns ....
In a controller I often see people use :
exports.myFunction = async function (req, res) { ......}
In other examples I see
const myFunction = async function (req, res) { ......}
module.exports = {myfunction}
-
what is the advantage of declaring the function as constant then exporting it vs exporting it as part of the definition? Is it just style, or will it make the code more testable or something else?
-
I have seen that people code services as classes and export the whole class. Is this best practice?
-
Why not define controllers as classes, and why not export the class?
I see these patterns mixed up in various articles talking about patterns and practices and haven't got my head around the nuances.
Thanks.
Aucun commentaire:
Enregistrer un commentaire