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

ip-location

v1.0.1

Published

Get an IP or hostname location.

Downloads

2,523

Readme

ip-location

Fetch the location of an IP address, host name, or your own location.

Uses freegeoip.net to query for information. freegeoip.net uses MaxMind Geolite 2.

Install

npm i --save ip-location

Usage

With Callbacks

var ipLocation = require('ip-location')

ipLocation('github.com', function (err, data) {
  console.log(data)
})

Outputs:

{ ip: '192.30.252.129',
  country_code: 'US',
  country_name: 'United States',
  region_code: 'CA',
  region_name: 'California',
  city: 'San Francisco',
  zip_code: '94107',
  time_zone: 'America/Los_Angeles',
  latitude: 37.7697,
  longitude: -122.3933,
  metro_code: 807 }

With Promises

var ipLocation = require('ip-location')

ipLocation('github.com')
.then(function (data) {
  console.dir(data)
})
.catch(function (err) {
  console.error(err)
})

Set Your Own Promise Implementation

You can set your own Promise library if you want to use Bluebird or are using Node v0.10.

var ipLocation = require('ip-location')

ipLocation.Promise = require('bluebird')

Use in Browser / or Use Own HTTP Library

If you want to use this in the browser, you must bring your own http GET library to the party. I'd recommend: xhr or fetch.

var ipLocation = require('ip-location')

ipLocation.httpGet = function (url, callback) {
  fetch(url).then(function (resp) {
    return resp.text() // don't use json()
  }).then(function (text) {
    resp.body = text // body should always be set to a string
    callback(null, resp)
  }).catch(function (err) {
    callback(err)
  })
}

Fetch Your Location

Just pass in an empty string.

ipLocation('', function (err, myLocation) {
  console.dir(myLocation)
})

Related

License

MIT - Copyright (c) JP Richardson