Tuesday 11 April 2017

Express return value from method with callback

Why does this

router.get('/eventTest/:id', function (req, res) {

var event = Event.getEventById(req.params.id, function (err, rows) {
    if(err) {
        return err;
    } else {
        return rows;
    }
});

res.json(event);

});

returns { "domain": null, "_events": {}, "_eventsCount": 0, "_callSite": {}, "_ended": false, "_idleNext": null, "_idlePrev": null, "_idleStart": null, "_idleTimeout": -1, "_repeat": null, "sql": "select * from event where id=?", "values": [ "1" ], "typeCast": true, "nestTables": false, "_resultSet": null, "_results": [], "_fields": [], "_index": 0, "_loadError": null }

rather than the actual values like it does when I use res.json(rows) inside the Event.getEventById callback?

I need this in order to call multiple methods and add them to an object and then send that object in JSON

Thank you



via Nuno Bettencourt

No comments:

Post a Comment