我按照本教程编写了一些来自Android的MongoDB的坐标:http://www.learn2crack.com/2014/04/android-login-registration-nodejs-server.html
当我尝试从应用程序连接时,我在服务器中收到以下错误
ReferenceError: coord is not defined
at Object.handle (/root/gpsavior/routes/routes.js:12:5)
at next_layer (/root/gpsavior/node_modules/express/lib/router/route.js:103:13)
at Route.dispatch (/root/gpsavior/node_modules/express/lib/router/route.js:107:5)
at c (/root/gpsavior/node_modules/express/lib/router/index.js:195:24)
at Function.proto.process_params (/root/gpsavior/node_modules/express/lib/router/index.js:251:12)
at next (/root/gpsavior/node_modules/express/lib/router/index.js:189:19)
at next_layer (/root/gpsavior/node_modules/express/lib/router/route.js:77:14)
at next_layer (/root/gpsavior/node_modules/express/lib/router/route.js:81:14)
at Route.dispatch (/root/gpsavior/node_modules/express/lib/router/route.js:107:5)
at c (/root/gpsavior/node_modules/express/lib/router/index.js:195:24)
POST /coord 500 1ms - 842b
这是我的routes.js(我只是把它来测试它并且它有效)
module.exports = function(app) {
app.get('/', function(req, res) {
res.end("gpsavior");
});
app.get('/coord', function(req, res) {
res.end("olakase");
});
app.post('/coord',function(req,res){
var num = req.body.num
var lat = req.body.lat;
var longi = req.body.longi;
coord.coord(num,lat,longi,function (found) { <---This one is line 12
console.log(found);
res.json(found);
});
});
和coord.js
var mongoose = require('mongoose');
var user = require('config/models');
exports.coord = function(num,lat,longi,callback) {
var num = num;
var lat = lat;
var longi =longi;
var coord = new user({
num: num,
lat: lat,
longi: longi });
coord.save();
callback({'response':"OK",'res':true});
}
答案 0 :(得分:1)
在我看来,您遗漏了require('coord.js');
routes.js