{"id":13465016,"url":"https://github.com/pbojinov/request-ip","last_synced_at":"2025-05-14T07:09:36.180Z","repository":{"id":12381787,"uuid":"15033690","full_name":"pbojinov/request-ip","owner":"pbojinov","description":"A Node.js module for retrieving a request's IP address on the server.","archived":false,"fork":false,"pushed_at":"2023-11-21T17:33:39.000Z","size":1014,"stargazers_count":848,"open_issues_count":31,"forks_count":103,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-11T02:51:35.221Z","etag":null,"topics":["address","ip","nodejs","nodejs-library","npm","request"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/request-ip","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pbojinov.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-12-08T23:36:05.000Z","updated_at":"2025-04-09T12:04:48.000Z","dependencies_parsed_at":"2024-06-18T11:27:59.859Z","dependency_job_id":null,"html_url":"https://github.com/pbojinov/request-ip","commit_stats":{"total_commits":138,"total_committers":28,"mean_commits":4.928571428571429,"dds":"0.34782608695652173","last_synced_commit":"e1d0f4b89edf26c77cf62b5ef662ba1a0bd1c9fd"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pbojinov%2Frequest-ip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pbojinov%2Frequest-ip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pbojinov%2Frequest-ip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pbojinov%2Frequest-ip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pbojinov","download_url":"https://codeload.github.com/pbojinov/request-ip/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254092787,"owners_count":22013290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["address","ip","nodejs","nodejs-library","npm","request"],"created_at":"2024-07-31T14:00:55.142Z","updated_at":"2025-05-14T07:09:31.163Z","avatar_url":"https://github.com/pbojinov.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Repository"],"sub_categories":["Network"],"readme":"# request-ip\n\nA tiny Node.js module for retrieving a request's IP address. \n\n![](https://nodei.co/npm/request-ip.png?downloads=true\u0026cacheBust=3)\n\n[![CI](https://github.com/pbojinov/request-ip/actions/workflows/ci.yml/badge.svg)](https://github.com/pbojinov/request-ip/actions/workflows/ci.yml)\n[![Coverage Status](https://coveralls.io/repos/pbojinov/request-ip/badge.svg)](https://coveralls.io/r/pbojinov/request-ip)\n![](https://img.shields.io/npm/l/express.svg)\n[![npm version](https://badge.fury.io/js/request-ip.svg)](https://badge.fury.io/js/request-ip)\n\n## Installation\n\nYarn\n```\nyarn add request-ip\n```\n\nnpm\n```bash\nnpm install request-ip --save\n```\n    \n## Getting Started\n\n```javascript\nconst requestIp = require('request-ip');\n\n// inside middleware handler\nconst ipMiddleware = function(req, res, next) {\n    const clientIp = requestIp.getClientIp(req); \n    next();\n};\n\n// on localhost you'll see 127.0.0.1 if you're using IPv4 \n// or ::1, ::ffff:127.0.0.1 if you're using IPv6\n```\n\n### As Connect Middleware\n\n```javascript\nconst requestIp = require('request-ip');\napp.use(requestIp.mw())\n\napp.use(function(req, res) {\n    const ip = req.clientIp;\n    res.end(ip);\n});\n```\n\nTo see a full working code for the middleware, check out the [examples](https://github.com/pbojinov/request-ip/tree/master/examples) folder.\n\nThe connect-middleware also supports retrieving the ip address under a custom attribute name, which also works as a container for any future settings. \n\n## How It Works\n\nIt looks for specific headers in the request and falls back to some defaults if they do not exist.\n\nThe user ip is determined by the following order:\n\n1. `X-Client-IP`  \n2. `X-Forwarded-For` (Header may return multiple IP addresses in the format: \"client IP, proxy 1 IP, proxy 2 IP\", so we take the first one.)\n3. `CF-Connecting-IP` (Cloudflare)\n4. `Fastly-Client-Ip` (Fastly CDN and Firebase hosting header when forwared to a cloud function)\n5. `True-Client-Ip` (Akamai and Cloudflare)\n6. `X-Real-IP` (Nginx proxy/FastCGI)\n7. `X-Cluster-Client-IP` (Rackspace LB, Riverbed Stingray)\n8. `X-Forwarded`, `Forwarded-For` and `Forwarded` (Variations of #2)\n9. `appengine-user-ip` (Google App Engine)\n10. `req.connection.remoteAddress`\n11. `req.socket.remoteAddress`\n12. `req.connection.socket.remoteAddress`\n13. `req.info.remoteAddress`\n14. `Cf-Pseudo-IPv4` (Cloudflare fallback)\n15. `request.raw` (Fastify)\n\nIf an IP address cannot be found, it will return `null`.\n\n## Samples Use Cases\n\n* Getting a user's IP for geolocation.\n\n\n## Running the Tests\n\nMake sure you have the necessary dev dependencies needed to run the tests:\n\n```\nnpm install\n```\n\nRun the integration tests\n\n```\nnpm test\n```\n\n## Building\n\nCompiles the current ES6 code to ES5 using Babel.\n\n```\nnpm build\n```\n\n## Release Notes\n\nSee the wonderful [changelog](https://github.com/pbojinov/request-ip/blob/master/CHANGELOG.md)\n\nTo generate a new changelog, install [github-changelog-generator](https://github.com/skywinder/github-changelog-generator) then run `npm run changelog`. This will require being on Ruby \u003e= 3\n\n## Contributors\n\nThank you to all the [contributors](https://github.com/pbojinov/request-ip/graphs/contributors)!\n\n## License\n\nThe MIT License (MIT) - 2022\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpbojinov%2Frequest-ip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpbojinov%2Frequest-ip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpbojinov%2Frequest-ip/lists"}