Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including lrm-graphhopper with all npm packages installed. Try it out:

var lrmGraphhopper = require("lrm-graphhopper")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

lrm-graphhopper v1.3.0

Support for GraphHopper in Leaflet Routing Machine

Leaflet Routing Machine / GraphHopper

npm version

Extends Leaflet Routing Machine with support for GraphHopper.

Some brief instructions follow below, but the Leaflet Routing Machine tutorial on alternative routers is recommended.


Go to the releases page to get the script to include in your page. Put the script after Leaflet and Leaflet Routing Machine has been loaded.

To use with for example Browserify:

npm install --save lrm-graphhopper


There's a single class exported by this module, L.Routing.GraphHopper. It implements the IRouter interface. Use it to replace Leaflet Routing Machine's default OSRM router implementation:

var L = require('leaflet');
require('lrm-graphhopper'); // This will tack on the class to the L.Routing namespace

    router: new L.Routing.GraphHopper('your GraphHopper API key'),

Note that you will need to pass a valid GraphHopper API key to the constructor.

To keep track of the GraphHopper credits consumption, the application may listen to the response event fired by the Router object. This event holds the values from GraphHopper's response HTTP headers:

  • status: The HTTP status code (see GraphHopper error codes)
  • limit: The X-RateLimit-Limit header
  • remaining: The X-RateLimit-Remaining header
  • reset: The X-RateLimit-Reset header
  • credits: The X-RateLimit-Credits header
var router = myRoutingControl.getRouter();
  console.log('This routing request consumed ' + e.credits + ' credit(s)');
  console.log('You have ' + e.remaining + ' left');
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free