Package Status: Published and live on npm!
Install: npm install node-cloudflare-realip
npm Page: https://www.npmjs.com/package/node-cloudflare-realip
Also available via:
- Yarn:
yarn add node-cloudflare-realip - pnpm:
pnpm add node-cloudflare-realip - Bun:
bun add node-cloudflare-realip
- Validate Cloudflare IP ranges before trusting Cloudflare headers.
- Middleware for Express and hook for Fastify.
- Bundled
ranges.jsonwith a helper to refresh from Cloudflare.
load([callback])- load bundled ranges fromranges.json. Returns a Promise if no callback provided.updateFromCloudflare()- fetch the latest ranges from Cloudflare (returns a Promise).check(req)- returns true if the incoming connection appears to be from Cloudflare and CF headers exist.get(req)- returns the best candidate for the original visitor IP (CF headers or fallback to socket remoteAddress).express()- returns an Express middleware to automatically setreq.realIpand overridereq.socket.remoteAddresswhen appropriate.fastify()- returns a FastifyonRequesthook function.
The package is already published! To publish updates:
- Make your changes and commit them.
- Bump the version:
npm version patch(orminorormajor). - Test packaging locally:
npm pack. - Publish the update:
npm publish --access public. - Push tags to GitHub:
git push && git push --tags.