0.1.6 • Published 2 years ago

request-country v0.1.6

Weekly downloads
826
License
-
Repository
github
Last release
2 years ago

request-country NPM version

Get 2-letter country code from http request in nodejs.

Installation

npm i request-country

Usage

var http = require('http');
var requestCountry = require('request-country');
var server = http.createServer(function(req, res) {
  console.log(requestCountry(req));
  // If it cannot detect country code from request ip,
  // the function return false.
});

If you want to set default value for private network IPs, you can pass second argument. So if you open your site from private network or localhost it will be returned.

  requestCountry(req, 'US');

You can get country code from ip address string as requestCountry('2.2.2.2').

As Connect Middleware

var requestCountry = require('request-country');
app.use(requestCountry.middleware({
  attributeName: 'requestCountryCode', // default is 'requestCountryCode'
  privateIpCountry: 'US' // Result for private network IPs
}));

app.use(function(req, res) {
  res.end(req.requestCountryCode);
});

LICENSE

This library use the geoip-country for getting country code. geoip-country includes GeoLite2 ipv4 and ipv6 country data which created by MaxMind, available from https://www.maxmind.com. Thus, the license of this library is based on the GeoLite2 License. See the LICENSE file for details.

0.1.6

2 years ago

0.1.5

4 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

7 years ago

0.0.2

8 years ago

0.0.1

8 years ago