Nodejs Export

In the sample application, I saw a module with this code:

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 see that the mongoose and schema functions can be called from anywhere in the application, but I cannot get this logic.

+4
source share
1 answer

exports = mongoose = require('mongoose')

Creates a variable named moongoose and sets it equal to require('mongoose') .

mongoose.connect(config.db.uri)

Starts a connection to the database.

exports = Schema = mongoose.Schema

This makes the module export require('mongoose').Schema for any reason.

This could simply be written as:

 var mongoose = require('mongoose') mongoose.connect(config.db.uri) exports = Schema = mongoose.Schema 
0
source

All Articles