In a sample application I saw a module with a code like this:
exports = mongoose = require('mongoose')
mongoose.connect(config.db.uri)
exports = Schema = mongoose.Schema
Can someone explain what the above code means? After these three lines I can see that mongoose and Schema functions can be called from anywhere in the application but I can't get the logic behind this.
exports = mongoose = require('mongoose')
This creates a variable called moongoose
and sets it to be equal to require('mongoose')
.
mongoose.connect(config.db.uri)
This starts a connection with a database.
exports = Schema = mongoose.Schema
This makes the module export require('mongoose').Schema
for whatever reason.
This could be more simply written as:
var mongoose = require('mongoose')
mongoose.connect(config.db.uri)
exports = Schema = mongoose.Schema