# How to use turf.js in node-red

**URL:** <https://discourse.nodered.org/t/how-to-use-turf-js-in-node-red/50830>\
**Category:** General\
**Created:** [9 September 2021 21:52 UTC](https://discourse.nodered.org/t/how-to-use-turf-js-in-node-red/50830 "2021-09-09T21:52:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![trickermkd](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trickermkd/32/47770_2.png) [@trickermkd](https://discourse.nodered.org/u/trickermkd)\
**Post date:** [9 September 2021 21:52 UTC](https://discourse.nodered.org/t/how-to-use-turf-js-in-node-red/50830/1 "2021-09-09T21:52:32Z")

</div>

I am working on Node-Red, and for my project I also use turf.js, which can be installed on node-red as well ( `node-red-contrib-turf` ).

This is how the structure looks:

 ![Screenshot from 2021-09-09 23-32-28](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/7/9702bfda5e53e8f050cad08d59fbf9e3b4ae2d91.png)

With `functionOne` having this code:

```auto
msg.topic = "point";
msg.payload = [[-75.343, 39.984]];
return msg;

```

And `functionTwo` :

```auto
pt = msg.payload
msg.topic = "buffer";
msg.payload = [pt, 5, {units: 'kilometers'}];

return msg;

```

So, the first function is used to produce a point of type `Feature` as stated in the [docs](https://turfjs.org/docs/#buffer) and I am passing it to the second one where I save it in the variable `pt` and then when I execute the whole thing it does not happen anything.

Does someone know what my mistake is?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [9 September 2021 22:13 UTC](https://discourse.nodered.org/t/how-to-use-turf-js-in-node-red/50830/2 "2021-09-09T22:13:17Z")

</div>

I have not used this node but looking at the example on your link, the payload for the point might be incorrect

> [@trickermkd](#):
>
> `msg.payload = [[-75.343, 39.984]];`

try `msg.payload = [-75.343, 39.984];` instead.

Also, put debug nodes after each node to verify each step returns what you expect.

---

<div class="post-metadata">

**Author:** ![trickermkd](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trickermkd/32/47770_2.png) [@trickermkd](https://discourse.nodered.org/u/trickermkd)\
**Post date:** [9 September 2021 22:16 UTC](https://discourse.nodered.org/t/how-to-use-turf-js-in-node-red/50830/3 "2021-09-09T22:16:14Z")

</div>

Thank you for taking a look. Actually, the first function works perfectly. I had a debug node over there and it does output a point. So, in my opinion it has to be something with the second function. Additionally, I also tried the double brackets on the second functions payload, but without any results.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [10 September 2021 10:04 UTC](https://discourse.nodered.org/t/how-to-use-turf-js-in-node-red/50830/4 "2021-09-10T10:04:48Z")

</div>

Did you put a `debug` node on the output of the 'createPoint' node to make sure that it is sending a msg to the next `function` node?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [10 September 2021 10:57 UTC](https://discourse.nodered.org/t/how-to-use-turf-js-in-node-red/50830/5 "2021-09-10T10:57:33Z")

</div>

At first glance you would seem to be correct and that code should work... but the node and also node-red-contrib-turfjs both seem to be several years old so the internal turf API may well have changed - You could try directly contacting the author to see if they are interested in fixing it.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [10 September 2021 13:10 UTC](https://discourse.nodered.org/t/how-to-use-turf-js-in-node-red/50830/6 "2021-09-10T13:10:49Z")

</div>

As I like turf - I've contacted the author myself - I have a patch for the node - will see if he wants to accept it.

---

<div class="post-metadata">

**Author:** ![bloigge](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bloigge/32/47983_2.png) [@bloigge](https://discourse.nodered.org/u/bloigge)\
**Post date:** [14 September 2021 14:27 UTC](https://discourse.nodered.org/t/how-to-use-turf-js-in-node-red/50830/7 "2021-09-14T14:27:45Z")

</div>

Thanks for reaching out. Haven't looked into this repo for a long time. I will give it a shot and update turf to the latest version - @dceejay - do you have a pull request for me?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [14 September 2021 14:52 UTC](https://discourse.nodered.org/t/how-to-use-turf-js-in-node-red/50830/8 "2021-09-14T14:52:37Z")

</div>

I may have 😉 .... [https://github.com/bloigge/node-red-contrib-turf/pull/5](https://github.com/bloigge/node-red-contrib-turf/pull/5)

@trickermkd - Once released to npm the OP flow above should then give

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/a/baf0bca4e102d543227ff6883ec69c181f60c036.jpeg)  
(If sent to worldmap)

```auto
[{"id":"bd598069a1cef449","type":"turf","z":"03086929b3b7f8ce","fn":"","name":"","x":410,"y":140,"wires":[["9c7463c2e60492ae","7712fc52a3289627"]]},{"id":"5bbd243899a9794c","type":"turf","z":"03086929b3b7f8ce","fn":"","name":"","x":670,"y":140,"wires":[["7712fc52a3289627"]]},{"id":"9c7463c2e60492ae","type":"function","z":"03086929b3b7f8ce","name":"","func":"msg.topic = \"buffer\";\nmsg.payload = [msg.payload, 5, { units: 'kilometers' }];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":140,"wires":[["5bbd243899a9794c"]]},{"id":"0bac9b156c763957","type":"inject","z":"03086929b3b7f8ce","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":140,"wires":[["2c03fced3d8db886"]]},{"id":"2c03fced3d8db886","type":"function","z":"03086929b3b7f8ce","name":"","func":"msg.topic = \"point\";\nmsg.payload = [[-75.343, 39.984]];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":140,"wires":[["bd598069a1cef449"]]},{"id":"7712fc52a3289627","type":"worldmap","z":"03086929b3b7f8ce","name":"","lat":"","lon":"","zoom":"","layer":"","cluster":"","maxage":"","usermenu":"show","layers":"show","panit":"false","panlock":"false","zoomlock":"false","hiderightclick":"false","coords":"false","showgrid":"false","allowFileDrop":"false","path":"/worldmap","x":820,"y":100,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![bloigge](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bloigge/32/47983_2.png) [@bloigge](https://discourse.nodered.org/u/bloigge)\
**Post date:** [14 September 2021 15:11 UTC](https://discourse.nodered.org/t/how-to-use-turf-js-in-node-red/50830/9 "2021-09-14T15:11:15Z")

</div>

Thank you! I have updated the repo and released it on npm.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [13 November 2021 15:11 UTC](https://discourse.nodered.org/t/how-to-use-turf-js-in-node-red/50830/10 "2021-11-13T15:11:43Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
