# Help needed with importing modules. How to specify that an exported function is a function?

**URL:** https://discourse.nodered.org/t/help-needed-with-importing-modules-how-to-specify-that-an-exported-function-is-a-function/65413
**Category:** General
**Tags:** function-node
**Created:** [21 July 2022 10:48 UTC](https://discourse.nodered.org/t/help-needed-with-importing-modules-how-to-specify-that-an-exported-function-is-a-function/65413 "2022-07-21T10:48:27Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![bwims](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bwims/32/64907_2.png) [@bwims](https://discourse.nodered.org/u/bwims)
#### Post date: [21 July 2022 10:48 UTC](https://discourse.nodered.org/t/help-needed-with-importing-modules-how-to-specify-that-an-exported-function-is-a-function/65413/1 "2022-07-21T10:48:27Z")

</div>

Hello,

I am migrating a module which I used to use with [node-red-contrib-function-npm](https://www.npmjs.com/package/node-red-contrib-function-npm) to the new(-ish) method of specifying the modules in the "Setup" tab of the function node.

If I import the example of [node-copy-paste](https://www.npmjs.com/package/copy-paste) This returns an object with properties which are functions and these work fine.

However, if I import the module I was using, [gps-to-gpx](https://www.npmjs.com/package/gps-to-gpx) , this module exports a function.

I specify it like this  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/8/f8e0bc2157a8eb9c7294c0b8c8d17f44e4602d0d.png)

When I attempt to call it as specified in the module description:

```auto
const gpx = createGpx(data.waypoints, {
  activityName: data.activityType,
  startTime: data.startTime,
});

```

It fails with the Typedef error that createGpx is not a function.

What am I missing? I'd be grateful for any help!

---

<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: [21 July 2022 10:53 UTC](https://discourse.nodered.org/t/help-needed-with-importing-modules-how-to-specify-that-an-exported-function-is-a-function/65413/2 "2022-07-21T10:53:20Z")

</div>

Put the following in your function - `node.warn({ "what-is-this": createGpx })`

What do you see in the debug panel?

* * *

It is likely you should import `gps-to-gpx` as `gpsToGpx` then call `gpsToGpx.createGpx`

---

<div class="post-metadata">

### Author: ![bwims](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bwims/32/64907_2.png) [@bwims](https://discourse.nodered.org/u/bwims)
#### Post date: [21 July 2022 11:08 UTC](https://discourse.nodered.org/t/help-needed-with-importing-modules-how-to-specify-that-an-exported-function-is-a-function/65413/3 "2022-07-21T11:08:03Z")

</div>

> [@Steve-Mcl](#):
>
> node.warn({ "what-is-this": createGpx })

Thanks for replying Steve!

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/c/ac28afc4a23fdba1d224803eb818059f9b877974.png)

I already tried the object idea, but I tried it again per your example:  
`"TypeError: gpsToGpx.createGpx is not a function"`

I'm not strong with coding, but the source code of the module contains this line:  
`export default function createGpx(waypoints, options = {})`

It's weird that the "what-is-this" reports a function, but then it isn't!

As ever, very grateful for the help so far!

```auto
Edit:

Apparently "Export Default" is part of ES6 which the release notes for V2 say is supported.

```

Edit 2:  
I noticed another difference between this module and others....

E.g. copy-paste definition states that it is imported like this:

```auto
var ncp = require("copy-paste");
 
ncp.copy('some text', function () {
  // complete...
})

```

Whereas gps-to-gpx is defined like this:  
`const createGpx = require('gps-to-gpx').default;`

Note the .default at the end of the require.

Is there a way of getting Node Red to import in that way?

---

<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: [21 July 2022 11:23 UTC](https://discourse.nodered.org/t/help-needed-with-importing-modules-how-to-specify-that-an-exported-function-is-a-function/65413/4 "2022-07-21T11:23:40Z")

</div>

> [@bwims](#):
>
> Note the .default at the end of the require.

Yes, so `gpsToGpx.default` should do the trick...

```auto
const data = {
  waypoints: [{ latitude: 51, longitude: -1 }, { latitude: 51, longitude: 0 }, { latitude: 51, longitude:1}],
    activityType: "run",
    startTime: new Date()
}
msg.payload = gpsToGpx.default(data.waypoints, {
  activityName: data.activityType,
  startTime: data.startTime,
})
return msg;

```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/9/c9e92d2f5a2ac2d1f4ce0eee2ae3b58843a82765.png)

---

<div class="post-metadata">

### Author: ![bwims](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bwims/32/64907_2.png) [@bwims](https://discourse.nodered.org/u/bwims)
#### Post date: [21 July 2022 11:31 UTC](https://discourse.nodered.org/t/help-needed-with-importing-modules-how-to-specify-that-an-exported-function-is-a-function/65413/5 "2022-07-21T11:31:02Z")

</div>

Hooray!

I was so close, too! Thanks very much Steve, you are an absolute hero! (I do regret reaching working age in the 70s instead of the 90s!)

Cheers!

Brian

---

<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: [4 August 2022 11:32 UTC](https://discourse.nodered.org/t/help-needed-with-importing-modules-how-to-specify-that-an-exported-function-is-a-function/65413/6 "2022-08-04T11:32:03Z")

</div>

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