GIScience / openrouteservice-js

:pushpin: The JavaScript API to consume openrouteservice(s) painlessly!
https://openrouteservice.org
Apache License 2.0
199 stars 34 forks source link

nodejs env not work #4

Closed stefanocudini closed 5 years ago

stefanocudini commented 6 years ago

I have this file test.js

var Openrouteservicejs = require('openrouteservice-js');
console.log(Openrouteservicejs);

running this in nodejs v10.6.0, cause:

$ node test.js 
Using browser-only version of superagent in non-browser environment
{}
stefanocudini commented 6 years ago

another simimlar problem, in this way like as documented in the README:

$ node index.js 
internal/modules/cjs/loader.js:583
    throw err;
    ^

Error: Cannot find module './OrsDirections'

I think this library is not organized according to the specific npm standards :(

stefanocudini commented 6 years ago

this work but isn't a standard node packaging: const OrsDirections = require("./node_modules/openrouteservice-js/src/OrsDirections");

related issue: https://github.com/Keplerjs/keplerjs-openrouteservice/issues/5

TimMcCauley commented 5 years ago

@stefanocudini can I close this issue?

stefanocudini commented 5 years ago

I'm sorry but this problem still remains

I think it's a pretty serious problem because, this causes difficulties for non-expert developers when I want to integrate this npm package into other software you should create a test page that included the npm package code in a standard way.

When I try to include this module in standard way:

var Ors = require('openrouteservice-js');

I'm recevice this error: Error: Cannot find module '../schemas/OrsmatrixSchema'

TimMcCauley commented 5 years ago

@stefanocudini very sorry about this, definitely my bad.. I moved the schemas to the src folder which are now respected by the npm build - please try version 0.0.9 from npm with npm i openrouteservice-js@0.0.9 - it works for my simple express setup:

var ors = require('openrouteservice-js');

// add your api_key here
const Directions = new ors.Directions({
  api_key: "XY"
});

Directions.calculate({
    coordinates: [[8.690958, 49.404662], [8.687868, 49.390139]],
....

Let me know if it works.