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

ipgeoblock-fixed

v0.1.6

Published

Middleware to allow or block requests based on origin country.

Downloads

21

Readme

node-ipgeoblock

Build Status

Node-ipgeoblock helps you secure your Express application by intoducing the blacklist of IPs, the blacklist of countries or the whitelist of countries.

This product includes GeoLite2 data created by MaxMind, available from http://www.maxmind.com.

Installation

First, run npm install node-ipgeoblock for your application.

Then download the latest version of MaxMind GeoLite2 Country Database and save it somewhere in the way that you application can access it. Make sure you download the database in MaxMind DB format. We will use ./GeoLite2-Country.mmdb in the following examples.

The last step is to register node-ipgeoblock middleware in your Express (or Connect) application.

IPs blacklist

var ipgeoblock = require("node-ipgeoblock");

var app = express();

app.use(ipgeoblock({
	geolite2: "./GeoLite2-Country.mmdb",
	blocked: ["192.168.0.1", "192.168.0.3", "192.168.0.4"]
}));

Countries blacklist

var ipgeoblock = require("node-ipgeoblock");

var app = express();

app.use(ipgeoblock({
	geolite2: "./GeoLite2-Country.mmdb",
	blockedCountries: [ "FR", "GB", "DE" ]
}));

When Countries Blackist is used you allow access for all IPs except IPs assigned to the countres from the blacklist. The Country Code MUST be upper case ISO 3166-2 Code.

Countries whitelist

var ipgeoblock = require("node-ipgeoblock");

var app = express();

app.use(ipgeoblock({
	geolite2: "./GeoLite2-Country.mmdb",
	allowedCountries: [ "FR", "GB", "DE" ]
}));

When Countries Whitelist is uses you restict access to the application only for the IPs assigned to the countries in the whitelist. The Country Code MUST be upper case ISO 3166-2 Code.

Combine IPs and countries blacklists

You can specify only countries blacklist or whitelist. You cannot use both at the same time. But you can use IPs blacklist and countries blacklist or whitelist.

var ipgeoblock = require("node-ipgeoblock");

var app = express();

app.use(ipgeoblock({
	geolite2: "./GeoLite2-Country.mmdb",
	blocked: ["192.168.0.1", "192.168.0.3", "192.168.0.4"],
	blockedCountries: [ "FR", "GB", "DE" ]
}));

Get country information for a request

Node-ipgeoblock adds IP country information to the request object.

app.use(function (req, res) {
	// MaxMind GeoLite2 country object
	console.log(JSON.stringify(req.location.country.data));
	
	// Country ISO 3166-2 code
	console.log(req.location.country.isoCode);
});

Custom access denied error hander

var ipgeoblock = require("node-ipgeoblock");

var app = express();

app.use(ipgeoblock({
	geolite2: "./GeoLite2-Country.mmdb",
	blocked: ["192.168.0.1", "192.168.0.3", "192.168.0.4"]
}, function (req, res) {
	res.statusCode = 500;
	res.end("Internal Server Error");
}));