In Node.js, how can I load my modules once and then use them throughout the app?
Posted
by
TIMEX
on Stack Overflow
See other posts from Stack Overflow
or by TIMEX
Published on 2013-12-15T19:51:30Z
Indexed on
2014/06/08
15:26 UTC
Read the original article
Hit count: 205
I want to create one global module file, and then have all my files require that global module file. Inside that file, I would load all the modules once and export a dictionary of loaded modules.
How can I do that?
I actually tried creating this file...and every time I require('global_modules')
, all the modules kept reloading. It's O(n).
I want the file to be something like this (but it doesn't work):
//global_modules.js - only load these one time
var modules = {
account_controller: '/account/controller.js',
account_middleware: '/account/middleware.js',
products_controller: '/products/controller.js',
...
}
exports.modules = modules;
© Stack Overflow or respective owner