returning results to outer function

Not quite sure how to return result to outer function, i want to call getListOfUsers() and get returned list of results

function getListOfUsers() {
    userlist.getUsers(function(next, res) {
       var result = JSON.parse(res);
       var listOfUsers = result.members.map(function (mem) {
            return mem.name;
        });
    });
}

If i return outside of the map, it will obviously return undefined, or null if i define it outside and initiate it inside. Using promises leaves me in same situation where my return is inside the 'then' function. Whats common practice here?

Seemingly, userlist.getUsers is an asynchronous function which means that you have to treat it asynchronously and use callbacks (via promises, continuations, or whichever style you prefer) to pass the retrieved data to other code.

function getListOfUsers(cb) {
    userlist.getUsers(function(next, res) {
       var result = JSON.parse(res);
       var listOfUsers = result.members.map(function (mem) {
           return mem.name;
       });
       cb(null, listOfUsers);
    });
}

Then instead of doing this:

var users = getListOfUsers();
// do things with users

You would do this:

getListOfUsers(function (err, users) {
    // do things with users
});