最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Where to place common functions in express.js? - Stack Overflow

programmeradmin0浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 12

They 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();
发布评论

评论列表(0)

  1. 暂无评论