Return values or export for nodejs function

Hi all,

Trying to get return value or export for a nodejs step, but I’m always receiving " No return values or exports for this step" even when I use different options.

This is original code to calculate distance between to longitude and latitude.
I’m getting correct calculated value for a code below, but don’t have option to use calculated output in next step.

How can I modify code to use later in next step value from function output, like: steps.nodejs.data ?

alert(calcCrow(59.3293371,13.4877472,59.3225525,13.4619422).toFixed(1));


    //This function takes in latitude and longitude of two location and returns the distance between them as the crow flies (in km)
    function calcCrow(lat1, lon1, lat2, lon2) 
    {
      var R = 6371; // km
      var dLat = toRad(lat2-lat1);
      var dLon = toRad(lon2-lon1);
      var lat1 = toRad(lat1);
      var lat2 = toRad(lat2);

      var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
        Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2); 
      var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
      var d = R * c;
      return d;
    }

    // Converts numeric degrees to radians
    function toRad(Value) 
    {
        return Value * Math.PI / 180;
    }

@mmesojedec in your code above, it looks like you’re calling the calcCrow function and running alert on the output - is that correct?

To return data for use in future steps, you’ll need to use return:

return calcCrow(59.3293371,13.4877472,59.3225525,13.4619422).toFixed(1)

or set properties of this:

this.data = calcCrow(59.3293371,13.4877472,59.3225525,13.4619422).toFixed(1)

See these docs for more information and let me know if that helps.

Hi @dylburger

Thanks for answer and provided solution.
This is exactly what I was looking.