Access function level variable from else inside while

Using node.js, I am trying to access a variable I declared at the beginning of a function from within an else statement in a do while loop:

function myFunction(){
    var limit = 2000;
    var count;
    var total;
    var runningTotal = 0;
    var url = 'http://example.com';
    var self = this;

    do{
        request({'url': url}, function (error, response, body) {
            if(error)logger.error(error);
            else{
                count = JSON.parse(body).count;
                console.log('count = ' + count);
                total = JSON.parse(body).total;
                console.log('total = ' + total);
                runningTotal+=count;
                console.log('running total = ' + runningTotal);
                var parsedBody = JSON.parse(body);
                self.parseResults(parsedBody.rows);
            }
        });
    } while(total > runningTotal);
}

When I run this code, the count, total and running total are logged out correctly, but the function level count, total and running total variables are undefined, so the while only runs once. Why is this, and how can I update these variables from within the else?

The request callback inside the loop is asynchronous, so you don't see the results of the request until later, after the loop has already completed. You need to reorganize the code to handle being async, something along these lines:

function myFunction(){
    var limit = 2000;
    var count;
    var total;
    var runningTotal = 0;
    var url = 'http://example.com';
    var self = this;

    doRequest();

    function doRequest() {
        request({'url': url}, function (error, response, body) {
            if(error)logger.error(error);
            else{
                count = JSON.parse(body).count;
                console.log('count = ' + count);
                total = JSON.parse(body).total;
                console.log('total = ' + total);
                runningTotal+=count;
                console.log('running total = ' + runningTotal);
                var parsedBody = JSON.parse(body);
                self.parseResults(parsedBody.rows);

                if (total > runningTotal) {
                    doRequest();
                }
            }
        });
    }
}

Also note that myFunction will return before any of the callbacks from request occur.

You do not understand what you are doing.
Your request is async.
So you can't just wrap it with while.

function myFunction(){
    var limit = 2000;
    var count;
    var total;
    var runningTotal = 0;
    var url = 'http://example.com';
    var self = this;

    function doRequest() {
         request({'url': url}, function (error, response, body) {
            if(error)logger.error(error);
            else{
                count = JSON.parse(body).count;
                console.log('count = ' + count);
                total = JSON.parse(body).total;
                console.log('total = ' + total);
                runningTotal+=count;
                console.log('running total = ' + runningTotal);
                var parsedBody = JSON.parse(body);
                self.parseResults(parsedBody.rows);
            }
            // repeat if need here
            if (total > runningTotal) doRequest();
        });          
    }

    doRequest();
}

About your code.
while iterations don't wait while request finished.
So, when while checks condition, both still equals to initial zero.