I want to apply Geoip to get my current city's name on Nodejs, then I try to install Geoip package by Npm, but it seems like that it has some mistake when running on Windows, so what should I do to solve the problem.
Asked
Active
Viewed 9,370 times
-4
-
3Please show the errors you're getting and what you've tried so people know where to start. – danieltan95 Dec 04 '17 at 11:24
-
1There are no errors, the Geoip package just not supports Windows. So what I want to ask is if there have some solutions instead. – answerhua Dec 04 '17 at 13:34
4 Answers
5
To get Country or City from IP Try this.it's very useful.
var geoip = require('geoip-lite');
$ npm install geoip-lite
var ip = "207.97.227.239";
var geo = geoip.lookup(ip);
console.log(geo);
{
range: [ 3479297920, 3479301339 ],
country: 'US',
region: 'TX',
city: 'San Antonio',
ll: [ 29.4889, -98.3987 ],
metro: 641,
zip: 78218
}

Imran
- 345
- 1
- 7
- 19
3
I've just published an NPM module for the IPLocate.io API which I created.
Super easy, no databases to download, and 1,500 free requests per day.
Install
npm install node-iplocate
Usage
const iplocate = require("node-iplocate");
iplocate("8.8.8.8").then(function(results) {
console.log("IP Address: " + results.ip);
// IP Address: 8.8.8.8
console.log("Country: " + results.country + " (" + results.country_code + ")");
// Country: United States (US)
console.log("Continent: " + results.continent);
// Continent: North America
console.log("Organisation: " + results.org + " (" + results.asn + ")");
// Organisation: Google LLC (AS15169)
console.log(JSON.stringify(results, null, 2));
/*
{
"ip": "8.8.8.8",
"country": "United States",
"country_code": "US",
"city": null,
"continent": "North America",
"latitude": 37.751,
"longitude": -97.822,
"time_zone": null,
"postal_code": null,
"org": "Google LLC",
"asn": "AS15169"
}
*/
});
// Or with callbacks
iplocate("8.8.8.8", null, function(err, results) {
// ...
console.log(JSON.stringify(results, null, 2));
});
// Provide an API key from IPLocate.io
iplocate("8.8.8.8", { api_key: "abcdef" }).then(function(results) {
// ...
});

ttarik
- 3,824
- 1
- 32
- 51
3
Try the IP2Location Node.js
https://github.com/ip2location-nodejs/IP2Location
Pre-requisite
Download the free LITE database from http://lite.ip2location.com/ and use below.
Install
npm install ip2location-nodejs
Usage
var ip2loc = require("ip2location-nodejs");
ip2loc.IP2Location_init("/path_to_your_database_file/your_BIN_file.BIN");
testip = ['8.8.8.8', '2404:6800:4001:c01::67', '2001:0200:0102:0000:0000:0000:0000:0000', '2001:0200:0135:0000:0000:0000:0000:0000', '2001:0200:017A:0000:0000:0000:0000:0000'];
for (var x = 0; x < testip.length; x++) {
result = ip2loc.IP2Location_get_all(testip[x]);
for (var key in result) {
console.log(key + ": " + result[key]);
}
}

Vlam
- 1,622
- 1
- 8
- 17
0
In case anyone is looking for a free - in memory soluition: https://www.npmjs.com/package/@avindak/xgeoip
const geoip = require('@avindak/xgeoip');
await geoip.load_memory();
//AU
let res = await geoip.resolve("1.1.1.1");
console.log(res.country_code);

Mitzi
- 2,652
- 1
- 20
- 15