Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
koa-location
Advanced tools
Koa middleware getting location information about client via user's IP.
Install with npm
$ npm install koa-location --save
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
}
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);
});
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.
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);
});
FAQs
Location information about client via user's IP.
We found that koa-location demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.