A simple Node application to return the IP of the client.
- Return the IP of the client by using the client connection or by using the header x-forwarded-for in either plain text, JSON or JSONP format.
- Download application
- Extract zip to a new directory where you want the app to reside
$ node app.js [port]
Default port is 80. You can specify a different port as command line argument or by defining an environment variable PORT.
To retrieve the IP use one of the following methods depending on the desired format:
Format | URL | Example |
---|---|---|
Plain text | http://your-server:[port] | Example |
JSON | http://your-server:[port]/?format=json | Example |
JSONP | http://your-server:[port]/?format=jsonp&jsonp=callback | Example |
The created JSON output looks like the following:
{ip: '127.0.0.1'}