javascript - is there better ways other than including require('mongoose') in every models file? -


i require mongoose in main app.js file once. can pass user.

var mongoose = require('mongoose'); 

without loading again? in each file. doesn't script job each time require same module?

var user = require('./models/user') 

from node documentation

modules cached after first time loaded. means (among other things) every call require('foo') same object returned, if resolve same file.

multiple calls require('foo') may not cause module code executed multiple times.

take @ caching.

it still possible require mongoose module globally. instead of var mongoose = require('mongoose'); write mongoose = require('mongoose');. able access mongoose other module.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -