I am using turf.js for the first time utilising its distance function part of @turf/distance module and when I run my server I get the issue saying, 'turf.distance' is not a function.
This is the code that generates the error.
https://jsfiddle.net/tcudrp7u/
Error show in Terminal
Gday @privateOmega
Because you're pulling in @turf/distance as a standalone module there is no global variable called turf
So you simply need to do something like
const distance= require('@turf/distance');
var from = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-75.343, 39.984]
}
};
var to = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-75.534, 39.123]
}
};
var units = "miles";
var distance = distance(from, to, units);
Hope that helps
@rowanwins thanks a lot for the solution. It worked perfectly.
Still getting same error