How to use external modules in a function node
STANDARD PREMIUM ULTIMATE
The function node allows you to write code in JavaScript and also to make use of libraries and modules shared on npm. This guide explains the basic steps of setting up a function node with an external module.
Double click on your function node to open the Properties panel.
Defining the modules
Navigate to the Setup tab of the function node. Here you can find the Modules section.
Click on the +add button to define a new module you want to install and use.
Enter the module name, for example:
@aws-sdk/client-s3
. This must match the exact name of the corresponding npm module hosted on https://www.npmjs.com/ .In the Import as field, define a new variable name, for example:
AwsSdkClientS3
. You will need to use the variable name in your code to import the module.
Using the modules in your code
Navigate to the On Message tab of the function node.
Import the module into your code by making use of the previously defined “Import as” variable name:
- JS
// import module const { S3Client, ListObjectsV2Command } = AwsSdkClientS3; // use imported module const client = new S3Client({credentials: {accessKeyId: msg.s3.accessKey,secretAccessKey: msg.s3.secretKey}, region: msg.s3.region}); //...
Click Done to close the panel.
Click Save to save the flow.
Installation process of external modules
The flow app will now detect that a new module was defined. If that module wasn’t already installed on the app, it will be automatically installed. During this process, you won’t be able to trigger the flow (e.g. manual triggers of inject nodes will be temporarily disabled).
Depending of the size and dependencies of the module, the installation usually takes one or multiple minutes. You can track the progress of the installation process in the Event Log.
To lookup the progress of the installation process, do the following steps:
Click on the menu icon in the top-right of the screen of the Flow Editor.
Click on View>Events to open the Event Log panel.
This is how a typical output of a module install process looks like:
2024-07-16T12:05:32.548Z pnpm install --prod --engine-strict --ignore-scripts --no-optional @aws-sdk/client-s3
2024-07-16T12:05:34.414Z [out] Progress: resolved 0, reused 1, downloaded 0, added 0
2024-07-16T12:06:18.184Z [out] Progress: resolved 279, reused 182, downloaded 97, added 0
2024-07-16T12:07:01.547Z [out] Progress: resolved 303, reused 206, downloaded 97, added 97, done
2024-07-16T12:07:06.748Z [out] dependencies:
2024-07-16T12:07:06.748Z [out] + @aws-sdk/client-s3 x.yyy.z
2024-07-16T12:07:06.748Z [out] optionalDependencies: skipped
2024-07-16T12:07:06.748Z [out] devDependencies: skipped
2024-07-16T12:07:06.796Z [out] Done in 1m 34.1s
Limitations for large modules
Installing large modules (typically those that are dozens of megabytes in size or have numerous dependencies) may exceed the available memory resources in your flow app, potentially causing the installation to fail. To mitigate this, consider using smaller breakout modules that provide only the necessary functionality (e.g., just the client for a specific AWS service).
If you encounter any issues, please report them to the support team.
Limitations for optional dependencies and scripts
Please note that the installation process restricts the installation of optional dependencies or scripts referenced in the npm package of an external module for security reasons. While most external modules should function without these resources, treating them as optional, some modules might strictly depend on them and may not work as expected. Usually, the author of the module will indicate such dependencies in the documentation.