To put it simply, you can't. To get values from functions like these, you must use a callback:
function add(post, callback) {
var word = new KeyWord({keyword: post.keyword});
word.save(function(err, word) {
if (err) {
if (err.code==11000) callback(post.keyword + ' is already added.');
else callback('Added : ' + post.keyword);
}
});
}
You'd then use the function like this:
add(post, function(result) {
// return value is here
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…