npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

location-from-ip

v1.0.1

Published

`location-from-ip` gives IP Geolocation information for every IPv4 or IPv6 address

Downloads

74

Readme

IP to Location

Npm package version Npm package yearly downloads

The npm package location-from-ip gives IP Geolocation information for every IPv4 or IPv6 address.

Currently, there are millions of different geolocation records in the database. Learn more, by reading the documentation.

Installation

You can both use this package from Node.js and in the browser with vanilla JavaScript.

npm install location-from-ip

If you want to clone the repository directly from GitHub instead:

git clone [email protected]:ipapi-is/ip_to_location.git

Usage from Node.js

If you want to lookup the IP address 144.168.164.55:

const { ipToGeolocation } = require('location-from-ip');

const ipAddresses = [
  '144.168.164.55',
  '167.99.241.66',
  '97.107.129.77',
  '85.10.199.76',
];

for (let ip of ipAddresses) {
  ipToGeolocation(ip).then(function (location) {
    console.log(`${ip} geolocation:`);
    console.log(location);
  });
}

which yields:

167.99.241.66 geolocation:
{
  continent: 'EU',
  country: 'Germany',
  country_code: 'DE',
  state: 'Hesse',
  city: 'Frankfurt am Main',
  latitude: 50.1109,
  longitude: 8.68213,
  zip: '07022',
  timezone: 'Europe/Berlin',
  local_time: '2023-10-22T13:36:01+02:00',
  local_time_unix: 1697974561,
  is_dst: true
}
85.10.199.76 geolocation:
{
  continent: 'EU',
  country: 'Germany',
  country_code: 'DE',
  state: 'Bavaria',
  city: 'Nürnberg',
  latitude: 49.45421,
  longitude: 11.07752,
  zip: '90403',
  timezone: 'Europe/Berlin',
  local_time: '2023-10-22T13:36:01+02:00',
  local_time_unix: 1697974561,
  is_dst: true
}
97.107.129.77 geolocation:
{
  continent: 'NA',
  country: 'United States',
  country_code: 'US',
  state: 'New Jersey',
  city: 'Morris Plains',
  latitude: 40.82177,
  longitude: -74.48099,
  zip: '07927',
  timezone: 'America/New_York',
  local_time: '2023-10-22T07:36:01-04:00',
  local_time_unix: 1697974561,
  is_dst: true
}
144.168.164.55 geolocation:
{
  continent: 'NA',
  country: 'Canada',
  country_code: 'CA',
  state: 'Quebec',
  city: "Baie-D'Urfé",
  latitude: 45.41397,
  longitude: -73.91586,
  zip: 'H9X',
  timezone: 'America/Toronto',
  local_time: '2023-10-22T07:36:01-04:00',
  local_time_unix: 1697974561,
  is_dst: true
}

Usage from the Browser

Copy the browser JavaScript bundle to your preferred location. After installing the module with

npm install location-from-ip

you can find the minified JavaScript here: node_modules/location-from-ip/dist/ipToGeolocation.min.js

<!doctype html>

<html lang="en">

<head>
  <meta charset="utf-8">
  <title>IP to Geolocation Example in Browser</title>
  <meta name="description" content="IP to Geolocation Example">
  <meta name="author" content="ipapi.is">
</head>

<body>
  <pre id="location"></pre>
  <script type="text/javascript" src="dist/ipToGeolocation.min.js"></script>
  <script type="text/javascript">
    ipToGeolocation('43.33.44.11').then((res) => {
      document.getElementById('location').innerText = JSON.stringify(res, null, 2);
    });
  </script>
</body>

</html>

Use the Database Directly

This package uses the ipapi.is geolocation database in order to avoid shipping a huge database in the npm module. If you have a large volume of IP addresses to lookup, you can download the full & free Geolocation Database.

GitHub mirror of the database: Geolocation Database