Importing function from Node.js module

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.)

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

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.

Welcome to forums @dazfitzg.

You cant require or import in function nodes.

Please see a recent post on how to do it Here

EDIT:
Seems you have already tried that :man_facepalming:

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

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