多个app.post请求,但我得到asertion错误nodejs

时间:2017-01-15 14:18:34

标签: node.js mongodb request handler restify

发布请求一些,但我无法发出多个帖子请求或获取请求 当我写多个app.post()或app.get时,我收到错误此错误: 断言错误:(函数)是必需的如何解决这个问题让所有人...

APPjs

var restify = require('restify');
var config = require('./config');
var app = restify.createServer({name:'REST-api'});

app.use(restify.fullResponse());
app.use(restify.bodyParser());
app.use(restify.queryParser());

app.listen(config.port, function() {
    console.log('server listening on port number', config.port);

});
var routes = require('./routes')(app);

Route.JS

module.exports.my = function(app) {
    var user = require('./controllers/userController');
    var location=require('./controllers/locationController');
    var ilan=require('./controllers/ilanController');

    app.get('/', function(req, res, next) {
        return res.send("WELCOME TO REST API");
    });


        //User get and create
       app.post('/createUser', user.createUser); //Create Student API

       app.get('/getUser',user.getUser);

          //Ilan get and create

        app.post('/createIlan',ilan.createilan);
        app.get('/getIlan',ilan.getian);

              //Location

         app.get('/getlocation', location.getLocation);

};

DB.js

var mongoose = require('mongoose');
var config = require('./config');

mongoose.connect(config.dbPath);
var db = mongoose.connection;

db.on('error', function () {
    console.log('error occured from db');
});

db.once('open', function dbOpen() {
    console.log('successfully opened the db');
});

exports.mongoose = mongoose;

1 个答案:

答案 0 :(得分:0)

Assertion error :(function) is required - 这是错误的头。您应该阅读跟踪此错误。希望这会有所帮助。