I am wondering where mon 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.
I am wondering where mon 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.
Share Improve this question edited Sep 25, 2014 at 12:03 Alvaro asked Sep 25, 2014 at 11:42 AlvaroAlvaro 41.6k31 gold badges172 silver badges347 bronze badges1 Answer
Reset to default 12They should be placed in an include that you require
from each route.
mon.js
function Common(){}
Common.prototype.method1 = function(){}
Common.prototype.method2 = function(){}
module.exports = new Common();
route.js
var mon = require('./mon');
mon.method1();
mon.method2();