Javascript: access parental function's variables

I have the following code (simplified):

function(req, res) {
  var path = 'login';

  req.on('end', function(data) {
    var post = parsevars(rawpost, '&');
    if (typeof post.username !== 'undefined' && typeof post.password !== 'undefined') {
      if (handlelogin(post.username, post.password))
        path = req.url;
    }
  });
}

The bold part is what doesn't work as expected :/
Any input on how to escape this scope restriction would be great.

It DID work, the code after it was just executed BEFORE the event handler.

Odd, that should work since req is in the outer scope of the closure.

However I think you'll find that the current req is also available as this within the callback, i.e.:

path = this.url;