express-ip is an Express.js middleware designed to integrate IP geolocation capabilities into web applications. It leverages the `geoip-lite` library to enrich the incoming `req` object with `ipInfo`, containing location data such as country, region, and city. The current stable version, 1.0.4, was last published over six years ago, indicating that the package is no longer actively maintained. This middleware relies on `geoip-lite`, which is a native Node.js API using MaxMind's GeoLite data. While `geoip-lite` offers fast, synchronous, in-memory lookups after an initial data load, users must manually update its geolocation database, and the free GeoLite data it uses is less accurate and less comprehensive than commercial alternatives. This package provides a straightforward way to add basic IP-based geolocation to Express applications but comes with the caveats of its unmaintained status and the limitations of its underlying data source.
npm install express-ipVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to integrate `express-ip` middleware and access IP geolocation data on the `req.ipInfo` object within an Express.js route.
Consider migrating to a more actively maintained IP geolocation solution or fork the repository for custom maintenance.
Refer to the `geoip-lite` documentation for instructions on how to manually update its data files. For higher accuracy, consider integrating a commercial GeoIP service.
Set `app.set('trust proxy', true);` or configure it with a specific IP range for trusted proxies in your Express application to correctly derive the client's IP.Be aware of this limitation when expecting detailed geolocation for IPv6 clients. More comprehensive IPv6 data typically requires commercial GeoIP databases.
Ensure `app.use(expressip().getIpInfoMiddleware);` is called before any routes that attempt to read `req.ipInfo`.
This is normal behavior. To test with public IPs, deploy the application or use tools that simulate external requests. The `express-ip` middleware will still process the loopback IP and return information (though limited for loopback).