# Importing function from Node.js module

**URL:** https://discourse.nodered.org/t/importing-function-from-node-js-module/77741
**Category:** General
**Tags:** function-node
**Created:** [20 April 2023 12:54 UTC](https://discourse.nodered.org/t/importing-function-from-node-js-module/77741 "2023-04-20T12:54:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![dazfitzg](https://avatars.discourse-cdn.com/v4/letter/d/e68b1a/32.png) [@dazfitzg](https://discourse.nodered.org/u/dazfitzg)
#### Post date: [20 April 2023 12:54 UTC](https://discourse.nodered.org/t/importing-function-from-node-js-module/77741/1 "2023-04-20T12:54:36Z")

</div>

Forgive me if I am doing something stupid, but I am just learning Node-Red and have a little knowledge of JavaScript.

I am trying to import the GTFS node from NPM into my Node-Red flow using a Function Node.

The example script provided uses the import syntax which doesn't appear to be available in Node-Red ( I have modified it to get the config value from the passed in message and output any errors using the node.error function.)

```auto
import { importGtfs } from 'gtfs';

const config = JSON.parse(msg.payload);

try {
  importGtfs(config);
} catch (error) {
  node.error(error);
}

```

I removed the import and tried to add the module in the function node's setup tab.  
I can see that the module was downloaded and installed in the external modules folder, but I can't find a way to access the importGtfs function of the gtfs node module.  
I have tried declaring the module as gtfs and accessing the function as gtfs.importGtfs, but this errors with TypeError: Cannot read properties of undefined (reading 'importGtfs')"  
I tried a suggestion of using gtfs/importGtfs for the module name but this returns

```auto
Error: Cannot find module 'gtfs/importGtfs'
Require stack:
- /data/node_modules/gtfs/importGtfs

```

I have tried assigning the gtfs variable to the msg.payload to see what was returned but I just get undefined.

It would appear that the node is written using ES6, is this the cause of all my problems?

Any help would be appreciated.

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [20 April 2023 13:11 UTC](https://discourse.nodered.org/t/importing-function-from-node-js-module/77741/2 "2023-04-20T13:11:19Z")

</div>

Welcome to forums @dazfitzg.

You cant `require` or `import` in function nodes.

Please see a recent post on how to do it [Here](https://discourse.nodered.org/t/howto-use-assert/77718)

EDIT:  
Seems you have already tried that 🤦‍♂️

> I removed the import and tried to add the module in the function node's setup tab.

---

<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: [19 June 2023 13:11 UTC](https://discourse.nodered.org/t/importing-function-from-node-js-module/77741/3 "2023-06-19T13:11:56Z")

</div>

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