# Snippet #4: LineRate and GeoIP Node.js module

**URL:** <https://community.f5.com/t/snippet-4-linerate-and-geoip-node-js-module/68221>\
**Category:** F5 Technical Articles\
**Tags:** nodejs, linerate\
**Created:** [December 30, 2014, 3:50am UTC](https://community.f5.com/t/snippet-4-linerate-and-geoip-node-js-module/68221 "2014-12-30T03:50:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Satoshi\_Toyosa1](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@Satoshi\_Toyosa1](https://community.f5.com/u/Satoshi_Toyosa1)\
**Post date:** [December 30, 2014, 3:50am UTC](https://community.f5.com/t/snippet-4-linerate-and-geoip-node-js-module/68221/1 "2014-12-30T03:50:00Z")

</div>

GeoIP allows you to find the geological location of a host based on its IP address. The information typically includes the country, city, latitude, and longitude. The types of data you get and their granularity and accuracy depend on database you use. This article demonstrates how we can utilize the [geoip-lite Node.js module](https://www.npmjs.com/package/geoip-lite) on LineRate. In this example, a LineRate VirtualServer injects two headers containing GeoIP information to the client requests in order to provide the information to the back-end HTTP servers for use in their applications.

To install the geoip-lite Node.js module, execute the following [LineRate command](http://docs.lineratesystems.com/093Release_2.5/200CLI_Reference_Guide/Exec_Commands/Scripting_Mode_Commands).

```tcl
scripting npm install geoip-lite

```

If you have received an error message, please refer to the section on LRS-26399 in [LineRate Release Notes, Version 2.5.0](https://support.f5.com/kb/en-us/products/linerate/releasenotes/product/relnote-linerate-2-5-0.html).

Here is the script. Make sure to change the virtual server ID in the 2nd argument of vsm.on (line #18).

```tcl
'use strict';
var geoip = require('geoip-lite');
var vsm = require('lrs/virtualServerModule');

var proc = function(servReq, servResp, cliReq) {
  var g = geoip.lookup(servReq.connection.remoteAddress);
  if (g) {
    if (g['ll']) {
      servReq.addHeader('Geo-Position', g['ll'].join(';'));
    }
    if (g['country']) {
      servReq.addHeader('Geo-Country', g['country']);
    }
  }
  cliReq();
}

vsm.on('exist', 'vs1', function(vso) {
  vso.on('request', proc);
};

```
