I am wondering where common functions should be placed in the express structure to be shared between different routes.
Is there any "best practice" for it? Nothing is mention in the documentation about it.
They should be placed in an include that you require
from each route.
common.js
function Common(){}
Common.prototype.method1 = function(){}
Common.prototype.method2 = function(){}
module.exports = new Common();
route.js
var common = require('./common');
common.method1();
common.method2();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With