An easier solution is to use the user:pass@host format directly in the URL.
Using the request library:
var request = require('request'),
username = "john",
password = "1234",
url = "http://" + username + ":" + password + "@www.example.com";
request(
{
url : url
},
function (error, response, body) {
// Do more stuff with 'body' here
}
);
I've written a little blogpost about this as well.