I have a user.js file:
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/dbName');
var User = mongoose.model('user', { username: String, password: String });
exports.User = User;
I am accessing the exposed User variable in other files.
However, I changed the file to this according to docs:
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/dbName');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function callback () {
console.log('connection open');
var Schema = mongoose.Schema;
var User = mongoose.model('user', { username: String, password: String });
exports.User = User;
});
However, the User variable is undefine now in the other file.
Why is it so and how do I expose the User variable to other files?