【发布时间】:2017-03-06 15:00:42
【问题描述】:
抱歉,如果标题描述性不强。
我正在使用 Node 并尝试使用 export.module 来获得干净的代码。
app.js
// ...
require('./router')(app);
module.exports = app;
router.js
cloudant = require("./helpers/cloudant")
// ...
module.exports = (app) => {
// ...
app.post("/statsPage", function(req, res) {
// ...
var a = cloudant.listUsers();
console.log("from post ", a) // --> it shows ("undefined")
if(a == false || a == undefined ) {
res.render("error");
} else {
res.render("statsPage", {
results: a
});
}
cloudant.js
exports = module.exports = {}
exports.listUsers = function() {
db.find({selector: {_id:{ "$gt": 0}}}, function(err, body) {
if(err) {
console.log(err);
return false;
} else {
console.log(body.docs) // --> it shows results correctly
return body.docs;
}
});
}
我已经采用与其他“导出”方法相同的方式,例如“插入”,因此我确信这个问题与我的数据库连接或导出“配置”无关。
【问题讨论】:
-
很抱歉我不能使用标签 node。我需要更高的声誉:'(
标签: javascript node.js cloudant