I have this simple node app running a web server using express and basic-auth-connect .
I know that I can get the client IP address on app.get(...) using something like
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
But if the http authentication fails it doesn't get there ::
var express = require('express');
var app = express();
var basicAuth = require('basic-auth-connect');
app.set('port', (process.env.PORT || 5000));
app.use(basicAuth(function(user, pass){ 
    authState = 'someUserName' == user && 'somePassword' == pass;
    console.log(user, pass, authState);
    // NEED the IP here ...         
    return authState;
}));
app.get('*', function(req, res) {
    var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
    console.log(ip);
    res.sendFile(__dirname + '/');
});
app.listen(app.get('port'), function() {
    console.log('Node app is running on port', app.get('port'));
});
