I understand the concept of module.exports as being a container object, with property exports, which is returned when required.
But what is the purpose of "const foo =" here?
edit:
(Module user.js)
const User = module.exports = mongoose.model('User', userSchema);
module.exports.getUserById = function(id, callback){
User.findById(id, callback);
}
Okay. That makes sense now that I typed out the context. I initially misread " User .findById" as a different var (const). That was embarrassing!
This is what module looks like:
var module = {
exports: {
yadablah: function(){
//code
}
} };
foo
and module.exports
both reference to the same object here that is function
yadablah()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.