Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

koa-location

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-location

Location information about client via user's IP.

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

koa-location

Koa middleware getting location information about client via user's IP.

Install


Install with npm

$ npm install koa-location --save

Usage

This module works detects the location of client by requests to following providers:

Example of the object you will get with location information

{
 code: "BG",
 country: "Bulgaria",
 region: "Burgas",
 city: "Burgas",
 latitude: 42.5,
 longitude: 27.4667
}
Example without auto detecting of location
var Koa = require('koa');
var app = new Koa();
var location = require('koa-location');

app.use(location());

app.use(async (ctx, next) => {
	await ctx.request.detect();
	ctx.body = 'Ce Kavo';
	console.log(ctx.request.location); // => getting the location info
});

var port = 8000;
app.listen(port, ()=> {
	console.log('Сервер работает на порту ' + port);
});
Example with auto detecting of location
var Koa = require('koa');
var app = new Koa();
var location = require('koa-location');

app.use(location({
	autoDetect: true
}));

app.use(async (ctx, next) => {
	ctx.body = 'Ce Kavo';
	console.log(ctx.request.location);  // => getting the location info
});

var port = 8000;
app.listen(port, ()=> {
	console.log('Сервер работает на порту ' + port);
});

If you not set to true the autoDetect option you need for calling additionaly the detect() function of the request object.

By default, autoDetect is false.

Support for FreeUlrs when autoDetect is true

When autoDetect is true, the detecting of location will not runs.

var Koa = require('koa');
var app = new Koa();
var location = require('koa-location');

app.use(location({
	autoDetect: true,
	freeUrls: ['/', '/cekavo','/hello']
}));

app.use(async(ctx, next) => {
	ctx.body = 'Ce Kavo';
	// detecing will runs if request url is not included in the array of free urls
	console.log(ctx.request.location); 
});

var port = 8000;
app.listen(port, () => {
	console.log('Сервер работает на порту ' + port);
});

Keywords

FAQs

Package last updated on 16 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc