
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
geolang-express
Advanced tools
A simple geolocation middleware for Express.js to set site lang by client IP.
A simple geolocation middleware for Express.js. This module expose countryLang
and object with more data countryData
on app.locals making data visibles in views too.
Also, set the session cookieLangName
with the language of visitors country, useful for i18n modules.
NOTE: When using this module, we recommend also using the i18n-express module, which use the cookieLangName
session to set i18n translations according that value.
$ npm install geolang-express
var geolang=require("geolang-express");
app.use( geolang(options) );
cookieLangName
: (default: ulang
) If you provide a cookie name, try to get user lang from this session/cookie.defaultCountry
: (default: US
) Default country, for example if the IP is 127.0.0.1siteLangs
: (default: ['en']
) Array of supported langs. (posbile values for clang and json files. see i18n-express)In your Express app.js:
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var i18n=require("i18n-express");
var geolang=require("geolang-express");
var indexRoutes = require('./routes/index');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(session({
secret: 'secret',
saveUninitialized: true,
resave: true
}));
app.use(geolang({
siteLangs: ["en","es"],
cookieLangName: 'ulang'
}));
/*
//Read documentation if you need to use i18n-express package
app.use(i18n({
translationsPath: path.join(__dirname, 'i18n'),
siteLangs: ["en","es"],
cookieLangName: 'ulang'
}));
*/
app.use('/', indexRoutes);
module.exports = app;
Now in your ejs view you have countryLang
and object with more data countryData
:
<div>
<p>Language by Country IP set to: <%=countryLang%></p>
</div>
Or in your handlebars view:
<div>
<p>Language by Country IP set to: <%=countryLang%></p>
</div>
MIT
FAQs
A simple geolocation middleware for Express.js to set site lang by client IP.
The npm package geolang-express receives a total of 44 weekly downloads. As such, geolang-express popularity was classified as not popular.
We found that geolang-express 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
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.