モジュール関数から結果を返すのに問題があります。
以下は、私が作業している2つのファイルです。
エクスポートされた関数を呼び出すと、何も返されません。
理由に関する提案/修正はありますか? コールバックと関係がありますか?
モデル/index.js
module.exports = exports = function(library) {
modCodes.findOne({name: library}, {modcode:1}, function(err, mc) {
if (err) throw new Error(err);
var db = mongoose.createConnection('mongodb://localhost:27017/' + mc.modcode + '?safe=true');
var models = {
Books: db.model('books', require('./schemas/books'))
}
return models;
});
};
books.js
var Models = require('../models');
console.log(Models("myLibrary")); //return nothing