Today we’ll see how we can get our user’s city, state, and country location information using their IP address and a from a free library and database called IP2Location.
Since, when working locally in NodeJS/AdonisJS our IP address is going to be localhost (127.0.0.1), I’ve gone ahead and grabbed three different IP addresses from my VPN for us to use as examples.
Chicago, United States: 107.150.29.169
Frankfurt, Germany: 45.87.212.78
Stockholm, Sweden: 149.50.216.74
What we need to do now is get the location through some service, and then we can compare the location via the service by its accuracy for the VPN's name for the IP address listed above.
Adding IP2Location
Ready to get started?
Join Adocasts+ for $8/mo or sign into your account to get access to all of our lessons.