使用node.js执行GET请求时,我收到了TypeError。它看起来和我所有其他模块中的所有其他请求相同。在我创建的两个模块之间执行的代码中返回了错误,因此我不确定发生了什么。
错误:
TypeError: undefined is not a function
at Object.exports.getFollowingWatches (/Users/M/Desktop/Projects/BX-Server/modules/feed/feeddb.js:23:11)
at /Users/M/Desktop/Projects/BX-Server/modules/feed/index.js:55:5
at Layer.handle [as handle_request] (/Users/M/Desktop/Projects/BX-Server/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/M/Desktop/Projects/BX-Server/node_modules/express/lib/router/route.js:131:13)
at Route.dispatch (/Users/M/Desktop/Projects/BX-Server/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Users/M/Desktop/Projects/BX-Server/node_modules/express/lib/router/layer.js:95:5)
at /Users/M/Desktop/Projects/BX-Server/node_modules/express/lib/router/index.js:277:22
at Function.process_params (/Users/M/Desktop/Projects/BX-Server/node_modules/express/lib/router/index.js:330:12)
at next (/Users/M/Desktop/Projects/BX-Server/node_modules/express/lib/router/index.js:271:10)
at Function.handle (/Users/M/Desktop/Projects/BX-Server/node_modules/express/lib/router/index.js:176:3)
获取请求:
router.get("/getFollowingWatches", function(req, res, callback) {
var userId = req.query.userId;
var position = req.query.pos;
if ((!(userId >= 1 && userId <= 9223372036854775807)) || (userId == undefined)) { //max signed
res.status(400).send("userId invalid");
return;
}
if (!(position >= 0 && position <= 100000)) { //what is the optimal max number? should do something elegant when this number is reached
res.status(400).send("max position number exceeded");
return;
}
db.getFollowingWatches(userId, position, function(feed) {
if (!feed) {
res.status(404).send("feed could not be loaded");
} else {
res.json(feed);
}
});
});
db call:
exports.getFollowingWatches = function(userId, position, callback) {
//@TODO: update interval time
var sql = "SELECT p.profilename AS watchname, p.idperson AS watchid, b.idbounty, b.description, b.idcreatedfor, b.contenttype " +
"FROM bounty b " +
"INNER JOIN watch w ON b.idbounty = w.idbounty " +
"INNER JOIN person p ON p.idperson = w.idperson " +
"WHERE w.idperson IN (select beingfollowed from follow where isfollowing = ?) " +
"AND timewatched >= CURDATE() - INTERVAL 100 YEAR " +
"AND b.iscomplete = 0 " +
"LIMIT BY ?, ?";
var inserts = [userId, parseInt(position), 20];
sql = mysql.format(sql, inserts);
console.log("getFollowingWatches db function running... " + sql);
dbcommon.executestatement(pool, sql, callback); //this line executes but an error is returned before the if statement is hit back in the GET request
};
正在执行dbcommon.executestatement ...但在可以在GET请求中执行if语句之前,错误已被命中
答案 0 :(得分:0)
我没有在dbcommon.executeStatement中大写S。这已经解决了。编程,哈哈。