osrm-backend icon indicating copy to clipboard operation
osrm-backend copied to clipboard

How do I get node-osrm working?

Open billystalnaker opened this issue 9 years ago • 10 comments

Server: Ubuntu 14.0 I've cloned the osrm-backend git and followed these instructions: https://github.com/Project-OSRM/osrm-backend/wiki/Building-OSRM Now I need to get the node part running. I don't want to use osrm-routed because I need this to work on https. Any help would be appreciated.

billystalnaker avatar Oct 11 '17 17:10 billystalnaker

@billystalnaker easiest thing to do is just use the modules we've already published for the latest release:

npm install osrm

will get you the node bindings as a regular node module, and all the pre-processing tools in node_modules/osrm/lib/binding/osrm-extract, etc.

No need to build OSRM from scratch unless you need the bleeding edge, or want to work on the code.

danpat avatar Oct 11 '17 18:10 danpat

Once I run npm install osrm what js file do I run to get allow the server to run http requests? Thanks for that clarification.

billystalnaker avatar Oct 11 '17 18:10 billystalnaker

There is no server included, you'll need to build your own using express-js or the-like. The node bindings are designed to be called from your own node code.

There is a copy of osrm-routed in node_modules/osrm/lib/bindings/osrm-routed for testing.

There's a very simple example server here:

https://github.com/Project-OSRM/osrm-backend/blob/master/example/example.js

danpat avatar Oct 11 '17 18:10 danpat

@danpat I installed the osrm package via npm but do not see any bindings here: node_modules/osrm/lib/ There is only an index.js file

billystalnaker avatar Oct 11 '17 20:10 billystalnaker

Apparently I had a version of Node.js (4) that didn't work with the version of npm I had running and so the files were not there.

ERROR: npm is known not to run on Node.js v4.2.6 Node.js 4 is supported but the specific version you're running has a bug known to break npm. Please update to at least ${rel.min} to use this version of npm. You can find the latest release of Node.js at https://nodejs.org/

billystalnaker avatar Oct 11 '17 20:10 billystalnaker

This was helpful: https://stackoverflow.com/questions/46360567/error-npm-is-known-not-to-run-on-node-js-v4-2-6

billystalnaker avatar Oct 11 '17 20:10 billystalnaker

@billystalnaker ah, yes, the Node ecosystem has lots of warts like that.

I would recommend using nvm to control it - https://stackoverflow.com/a/46361315

The Node/npm packages that come with Ubuntu tend to be fairly dated, I would avoid them.

Note that we publish OSRM modules that are compatible with Node 4 and 6, but not 8 (yet).

danpat avatar Oct 11 '17 21:10 danpat

Thanks!

billystalnaker avatar Oct 11 '17 21:10 billystalnaker

@billystalnaker Can we close this issue? If there's no actual bug in OSRM, I'll pencil this one up to "the nodejs ecosystem is messy"

danpat avatar Oct 13 '17 15:10 danpat

Yes, that's fine by me.

billystalnaker avatar Oct 13 '17 16:10 billystalnaker