Q:

Callback is not defined in module.exports

I have a route like
var helper = require('./helper');

router.get('/create', function(req, res, next){
    helper.saveItem('itemId', function(err) {
        if(err) {
            return next(err);
        }
        next();
    });
});

and in helper helper.js
module.exports = {
    saveItem: function(id, callback) {
        var item = new ItemModel({Id: id});
        item.save().exec(callback);
    },
}

When I call saveItem, the 'id' parameter has the right value, but the callback is undefined. And I can not figure it why.

A:

use this code . Instead of giving exec method pass callback directly in save method.
module.exports = {
    saveItem: function(id, callback) {
        var item = new ItemModel({Id: id});
        item.save(callback);
    },
}

