Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
47 lines (35 sloc) 1.02 KB


Get the remote address of a request, with reverse-proxy support

build status


$ npm install addr

addr(req, [proxies])

  • req: an http.ServerRequest object.
  • proxies: an array of IP addresses of trusted proxies. If specified and the request doesn't come from one of these addresses, the X-Forwarded-For header will not be honored.
  • Returns: Remote IP address of the request, taken from the X-Forwarded-For header if it exists and the request is coming from a trusted proxy.


var addr = require('addr')
  , http = require('http')
  , port = 3000
  , proxies = ['']

http.createServer(function(req, res) {
  res.writeHead(200, {'Content-Type': 'application/json'});
  res.write(JSON.stringify({addr: addr(req, proxies)}));
}).listen(port, function() {
  console.log('test server running on port ' + port);



Something went wrong with that request. Please try again.