I currently have a function that is called from my router:
router.js:
var result = Api.getUser();
console.log(\"Result: \" + result);
You can't return
from an async function, you use a callback:
exports.getUser = function(req, result, callback) {
request.get({
uri: URL + '/user/me/',
headers: {Authorization: 'bearer ' + req.user.accessToken},
json: true
}, function(e, r, body) {
if(e) {
callback({error: true});
} else {
callback(body);
}
});
};
Api.getUser(req, result, function(user) {
console.log(user);
});