For more than a month, i've been working with project that involving nodejs. For someone who does not have javascript background like me, it was very tiring. I will tell another story in another post, but now i'll post about module.exports behavior.
Let's check following code
Ther first code
module.exports = function(db) {
var schema = require('../../config/schema.js').user(db.Schema);
return db.model('User', schema);
}
The second code
module.exports = function() {
var db = global.db;
var schema = require('../../config/schema.js').user(db.Schema);
return db.model('User', schema);
}
both code have different behavior, the first code will return the model object, the second code will return the function.
Have a nice time.
Comments