I'm having trouble with the following code snippet. I can't access userId from within the callback function, and I can't return whether whitelistedUserIds contains the userId or not. According to the debugger, when I step inside the callback, userId is undefined.
Could anyone explain why? and how to fix this? I've been off javascript for quite a while...
function userInWhitelist(userFileName) {
var userId = userFileName.replace('.txt', '');
request({
url: whitelistURL
}, function(err, resp, body, userId) {
if (resp.statusCode == 200) {
var users = JSON.parse(body).data;
var whitelistedUserIds = _.map(users, (user) => { return user.id; });
// How to access userId ??
// How to return whitelistedUserIds.includes(userId)
}
});