How / where should i use javascript?

Hello !

I’m trying to find out how should i use javascript to do my own routing.
I found out how to “lock” my application to work only for hiking or biking, so i already have my graph running properly.

But when i want to try out things like “alternative routes” and / or modify the parameters for this (and thus, have multiple hike paths, for example) i can only do this from the url directly.

I don’t know where to put it.
Is there somewhere i have to add the variable to the url using gh_request ?

I found out that i could just use javascript in index.html, but it requires an api key, but since i’m using the open source, i don’t really know how to avoid that “api key” step …

Thanks for the help, if i’m not really clear, let me correct :slight_smile:

You can use all clients without a valid API key, just set a fake one.

So i can either use :

var GraphHopperRouting = require('graphhopper-js-api-client/src/GraphHopperRouting');
and then use
var ghRouting = new GraphHopperRouting({key: defaultKey, host: host, vehicle: profile, elevation: false});
ghRouting.addPoint = blabla

or

var ghRouting = new GraphHopper.Routing({key: defaultKey, host: host, vehicle: profile, elevation: false});
if i want to use all the features ?

The usage is documented here: https://github.com/graphhopper/directions-api-js-client

Excuse me again, but i don’t understand how the “require” part works.

i tought the direction api client was already in the graphhopper project. well, it wasn’t

I did the npm install command and it included the direction client inside a node_module directory.
And actually the require('graphhopper-js-api-client'); doesn’t work, i guess it is because of the path.

Should i move the directory that is inside node_module/ to webapp/ ? or is it more specific ?

thanks for the answer

can you share me the code which you used for routing, unfortunately i am also stuck there.