Installing OSRM for node

As an alternative to apis such as Google Directions, the Open Source Routing Machine is a great project. While there is The Leaflet routing machine that interfaces to it, I'd much rather play with the routing engine so I can plot on Mapbox-gl (or any other mapping library). The routing engine is written in C++, but luckily (or so I thought), there is a node port:

Off I go and npm install osrm ... Except that it is throwing errors all over the console. A bit of digging into the issues on github told me that it doesn't just 'install' on node versions > 0.12, and I have node v.4.x. Which means I have to run a local version of node 0.12 (use nvm), then there's also a setup process before you can actually do anything. It took me a while going round and round before actually getting it up and running, so I thought I'd post some instructions here mainly as a reminder to myself if I ever need to do it again (or it may help someone)

  1. If you have a global node version > 0.12 (as of 20th Dec 2015-- it may well change in the future):
    • $ npm install -g nvm
    • in directory, $ nvm use 0.12 (so local 0.12 version)
  2. $ npm install osrm
  3. download the city/country/world extract of OSM data that you want -- a good source is
  4. put the .pbf file inside the osrm folder
  5. in the makefile provided, change the berlin-latest-... commands to the file extract that you have. E.g. in my case, using london, I have
  6. After the .hsgr has been built, use the module like so:
    var OSRM = require('osrm'); var osrm = new OSRM("node_modules/osrm/greater-london-latest.osrm");

** note that I have to put in the node_modules etc path in it other wise it complains it can't find the .osrm file...

Next up I'll put in a few more bits about how I'm using it if I ever figure it out ;)