npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

forwarded-for

v1.1.0

Published

Abstraction for retrieving ip address information from a Node.js connection. Searches for proxy headers before degrading req.address

Downloads

58,454

Readme

forwarded-for

Version npmBuild StatusDependenciesCoverage StatusIRC channel

When you are hosting your applications behind a reverse load balancer the incoming requests will no longer have the IP address of your user but of the load balancer as it forwards the request to your node instance. Most load balancers allow you to modify the headers of the request and add original request information in it.

This module makes it easier to find the correct IP address of your connection by detecting these headers that load balancers set and it will gracefully fall down to the original req.address that contained the IP address of the request inside node.js. In addition to gracefully degrading to the original request we also for other known locations of the address (which are usually set by frameworks such as SockJS and Socket.IO etc.)

Installation

The module is released in the npm registry:

npm install --save forwarded-for

Getting started

Let's start out with including the module in to your application:

'use strict';

var forwarded = require('forwarded-for');

The forwarded variable will now contain the function which parses out the request information for you in to a really simple object. This object contains the following properties:

  • port The remote port. It defaults to 0.
  • ip The string representation of the remoteAddress. It defaults to '127.0.0.1'.

When we fail to parse or detect an IP address we will use the default values to construct the object. To correctly parse the data the function requires the following arguments:

  • obj The socket like object that probably contains the remoteAddress
  • headers A reference to the HTTP headers of the request
  • whitelist, optional A white list of IP addresses of your load balancers so people cannot make fake requests with x-forwarded-for headers.

So with all the information combined, it would look something like this:

'use strict';

var forwarded = require('forwarded-for');

require('http').createServer(function (req, res) {
  var address = forwarded(req, req.headers);

  res.end('Your ip address is '+ address.ip);
}).listen(8080);

License

MIT