Problem using Node.js modules within n8n function node

Running n8n via npm
Operating system: Windows

A basic problem :slightly_smiling_face: I am new to n8n, trying to run Node.js modules in a function node but It does not work for me.

Any help is appreciated.

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hi P.Y.

any further Information would help.

How did you set up n8n?
Did you follow along the documentation/ set the environment variables?

To use NodeJS modules, you need to set the following environment variables:
export NODE_FUNCTION_ALLOW_BUILTIN=*
export NODE_FUNCTION_ALLOW_EXTERNAL=*

The first is for allowing internal libraries, and the second is for external npm libraries.

Then import the library in your code node, using commonjs syntax.
Ex:
const cheerio = require(β€˜cheerio’);

2 Likes

Many thanks Akram. This was very helpful, it worked!

1 Like

Glad it helped!

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