Gathering detailed insights and metrics for @supercharge/request-ip
Gathering detailed insights and metrics for @supercharge/request-ip
npm install @supercharge/request-ip
Typescript
Module System
Node Version
NPM Version
99.2
Supply Chain
100
Quality
79.4
Maintenance
100
Vulnerability
100
License
TypeScript (58.19%)
JavaScript (41.81%)
Total Downloads
5,065,773
Last Day
6,896
Last Week
32,838
Last Month
153,138
Last Year
2,023,851
66 Stars
52 Commits
5 Forks
3 Watching
2 Branches
3 Contributors
Latest Version
1.2.0
Package Id
@supercharge/request-ip@1.2.0
Unpacked Size
22.75 kB
Size
5.36 kB
File Count
9
NPM Version
8.5.1
Node Version
14.17.1
Cumulative downloads
Total Downloads
Last day
-19.8%
6,896
Compared to previous day
Last week
-20.7%
32,838
Compared to previous week
Last month
1.5%
153,138
Compared to previous month
Last year
22.2%
2,023,851
Compared to previous year
Retrieve a request’s IP address
Installation · Usage · Detecting the IP Address
Follow @marcuspoehls and @superchargejs for updates!
The @supercharge/request-ip
package provides a function to retrieve a request’s IP address.
npm i @supercharge/request-ip
1const RequestIp = require('@supercharge/request-ip') 2 3const ip = RequestIp.getClientIp(request) 4 5// for example '213.211.254.97' as an IP v4 address 6// or '2001:0db8:85a3:0000:0000:8a2e:0370:7334' as an IP v6 address 7// or 'undefined' if no IP address is available on the given request
Depending on your used web framework, you may use it in a middleware or route handler:
simple Express example
1const { getClientIp } = require('@supercharge/request-ip') 2 3const expressMiddleware = function (req, res, next) { 4 req.ip = getClientIp(req) 5 6 next() 7}
simple hapi route handler example:
1const Hapi = require('@hapi/hapi') 2const { getClientIp } = require('@supercharge/request-ip') 3 4const server = new Hapi.Server({ 5 host: 'localhost' 6}) 7 8server.route({ 9 method: 'GET', 10 path: '/login', 11 handler: (request, h) => { 12 const ip = getClientIp(request) 13 14 return h.response(ip) 15 } 16})
The client’s IP address may be stored in different locations of the request instance varying between services.
Here’s the order of locations in which the packages searches for the requesting IP address:
x-forwarded-for
: this header may contain multiple IP address for (client/proxies/hops). This package extracts and returns the first IP address.x-forwarded
, forwarded
, forwarded-for
as variants from x-forwarded-for
possibly configured by proxiesx-client-ip
possibly configured by nginxx-real-ip
possibly configured in nginxcf-connecting-ip
from Cloudflarefastly-client-ip
from Fastly and Firebasetrue-client-ip
from Akamai and Cloudflarex-cluster-client-ip
from Rackspacerequest.connection
and request.connection.socket
request.socket
request.info
request.raw
request.requestContext
A huge thank you to Petar Bojinov for his request-ip package. I was using Petar’s package for two years in my hapi-rate-limitor plugin. It seems Petar is busy with other work and I felt the need to create my own package providing the functionality to retrieve a request’s IP address.
Do you miss a way to find the request’s IP? We very much appreciate your contribution! Please send in a pull request 😊
git checkout -b my-feature
git commit -am 'Add some feature'
git push origin my-new-feature
MIT © Supercharge
superchargejs.com · GitHub @supercharge · Twitter @superchargejs
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/29 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More