とundefinedを返します。私のexportsファイルで私の結果 は記録されませんが、私は私のProjects.find
コール外の単純な文字列を返す場合、それは動作します。module.exportsは、私はマングースと私の<code>find</code>コールに<code>undefined</code>リターンを得続けるマングースコール
私はreq
& res
を渡しています。これらのファイルは、エクスポートファイルに正しく記録されているため、問題とは関係ありません。何が間違っているのでしょうか?それがためです
routes.js
var proj = require('./exports/projects');
app.use(function(req, res, next){
//repsonse: undefined
console.log('response: ' + proj.test(req, res));
next();
});
輸出/ projects.js
var Projects = require('../models/projects');
module.exports = {
test: function(req, res) {
Projects.find({'owner':req.user.id}, function(err, result) {
if (err) return '1';
if (!result)
return null;
else
return result;
});
}
};
モデル/ projects.js
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var shortid = require('shortid');
var Projects = new Schema({
projectid: String,
pname: { type: String, required: true, trim: true },
owner: { type: String, required: true, trim: true },
status: { type: String, default: '0' },
team: String,
archived: { type: Boolean, default: '0' },
created_at: Date
});
Projects.pre('save', function(next) {
var currentDate = new Date();
this.created_at = currentDate;
this.projectid = shortid.generate();
next();
});
module.exports = mongoose.model('Projects', Projects);
グレート答えのおかげで、私はそれはそれとは何かを知っていたが、私は、輸出と似たような状況がありましたそれがコールバックを必要としないように思えましたが、ページが代わりにレンダリングされたためである必要があります。総合的な答えにもう一度感謝します! – Aotik