The video provides a guide on how to integrate Node.js modules into n8n workflows, distinguishing between built-in modules that require activation and external modules that require installation and activation. It details the process for each using command-line instructions within a Docker environment, emphasizing changes to docker-compose.yml
and the creation of a Dockerfile
. The guide also covers the updated procedure for n8n updates when custom modules are in use.
Using Node.js Modules in n8n #
- Node.js modules may be required for complex n8n workflows.
- Modules are referenced by
require
in code nodes. - Some modules are built-in but need activation; others are external and need installation.
- A link to an article with a full list of built-in n8n modules is provided in the description.
Activating Built-in Modules (e.g., crypto
) #
- Error Identification: Running a test function shows
Cannot find module crypto
if a built-in module is not activated. - Accessing
docker-compose.yml
:- Navigate to the directory containing
docker-compose.yml
(e.g.,cd ~/n8n-docker-caddy
). - Open the file for editing (e.g.,
nano docker-compose.yml
).
- Navigate to the directory containing
- Modifying
docker-compose.yml
:- Add
NODE_FUNCTION_ALLOW_BUILTIN=crypto
under theenvironment
section. - Multiple built-in modules can be added as a comma-separated list (e.g.,
a,b,c
). - An asterisk (
*
) can activate all built-in modules, but it's best practice to activate only needed ones.
- Add
- Applying Changes:
- Save the
docker-compose.yml
file (Ctrl+X, Y, Enter). - Bring Docker down (
docker-compose down
). - Bring Docker back up (
docker-compose up -d
).
- Save the
- Verification: Re-running the n8n workflow should resolve the built-in module error.
Installing and Activating External Modules (e.g., express
) #
- Error Identification: If an external module is not installed, an error like
Cannot find module express
will occur. - Custom Image Requirement: External modules require building n8n with a custom Docker image. This process does not delete existing workflows.
- Creating a Dockerfile:
- Ensure you are in the same directory as
docker-compose.yml
. - Create or open a
Dockerfile
(e.g.,nano Dockerfile
). Note:Dockerfile
must have a capital 'D'. - Add the following content:
1FROM n8nio/n8n:latest 2USER root 3RUN npm install -g express
- To install multiple external modules, list them space-separated after
npm install -g
(e.g.,RUN npm install -g module1 module2
). - Save the
Dockerfile
(Ctrl+X, Y, Enter).
- Ensure you are in the same directory as
- Modifying
docker-compose.yml
for External Modules:- Open
docker-compose.yml
for editing (e.g.,nano docker-compose.yml
). - Remove the
image
line under then8n
section. - Replace it with
build: .
(this tells Docker to build from the current directory where the Dockerfile is). - Add
NODE_FUNCTION_ALLOW_EXTERNAL=express
to theenvironment
section. This can be added after theNODE_FUNCTION_ALLOW_BUILTIN
line if both are used. - Similar to built-in modules, multiple external modules can be a comma-separated list, or an asterisk (
*
) can be used to allow all installed external modules. Best practice is to allow only needed ones. - Save
docker-compose.yml
(Ctrl+X, Y, Enter).
- Open
- Applying Changes:
- Bring Docker down (
docker-compose down
). - Build the custom image (
docker-compose build
). This may take time and download files on first build. - Bring Docker back up (
docker-compose up -d
).
- Bring Docker down (
- Verification: Re-running the n8n workflow should show successful execution, confirming the external module is working.
Updating n8n with Custom Modules #
- For External Modules (and combinations):
- Bring Docker down:
docker-compose down
- Build the custom image again:
docker-compose build
- Bring Docker back up:
docker-compose up -d
- This sequence ensures the custom Dockerfile is rebuilt with the new n8n version.
- Bring Docker down:
- For Built-in Modules Only (no external modules):
- Pull the latest Docker image:
docker-compose pull
- Bring Docker down:
docker-compose down
- Bring Docker back up:
docker-compose up -d
- Pull the latest Docker image:
Summary Sections: #
- Introduction to Node.js Modules in n8n: Discusses the need for Node.js modules in complex n8n workflows and the two categories of modules (built-in and external).
- Activating Built-in Modules: Provides step-by-step instructions for enabling pre-installed Node.js modules like
crypto
through modifications to thedocker-compose.yml
file and Docker commands. - Installing and Activating External Modules: Details the more involved process for using modules not built into n8n, such as
express
, which requires creating aDockerfile
and further modifications todocker-compose.yml
, followed by building a custom Docker image. - Updating n8n with Custom Modules: Explains the different update procedures for n8n instances depending on whether only built-in modules or external modules have been integrated.
last updated: