写入 mongodb 成功,但服务器因错误而关闭

writing to mongodb succeeds, but server shuts down with errors

我在哪里可以读到节点控制台和我的浏览器生成的错误,以便我可以从中学习? 例如,浏览器控制台显示 net::ERR_CONNECTION_REFUSED 并且我的节点服务器向我抛出有关猫鼬等的错误

节点错误: ......./node_modules/mongoose/lib/utils.js:419 抛出错误; ^ TypeError: undefined 不是函数

节点代码

    app.post('/api/todos', function(req, res) {
    todo.create({
        text : req.body.text,
        done : true
    }, function(err, todo) {
        if (err) res.send(err);
        todo.find(function(err, todos){
            if(err)
                res.send(err)
            res.json(todos);
        });
    });
});

create 回调中的参数与模型同名,用 create 函数的结果覆盖更高范围的变量 todo,这不是一个模型,并且没有 find 方法。

重命名 todo 参数

app.post('/api/todos', function(req, res) {
    todo.create({
        text : req.body.text,
        done : true
    }, function(err, result) {
        if (err) res.send(err);

        todo.find(function(err, todos){
            if(err)
                res.send(err)

            res.json(todos);
        });
    });
});