- Bot & Beyond
- Posts
- N8N Local Setup & How To Use External Libraries In Code Node
N8N Local Setup & How To Use External Libraries In Code Node
A Step-by-Step Guide to Running N8n with Docker and Enabling External Libraries

Someone asked me how to use external libraries in code node in a comment of my code node video
Simple answer is to enable the environment variable NODE_FUNCTION_ALLOW_EXTERNAL
Here’s the long answer with how to enable it.
First let’s see how to install n8n locally.
There are many ways to do that, and you could use either Docker or npm.
I have only tried docker because I had docker installed already and I’m familiar with docker than npm.
Run Docker command
You can get n8n up and running by just running a docker command.

From N8n Docs
docker volume create n8n_data
This command creates a named volume in docker for saving data. But you really don’t need this.
This next command will create the volume for you if it doesn’t exist.
docker run -it --rm --name n8n -p 5678:5678 -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n
Let’s break it down
Part | Explanation |
---|---|
| This tells Docker to start a new container using the specified image. |
| Combines |
| Automatically removes the container when it stops. Prevents leftover containers from taking up space. Good for temporary use. |
| Names the container |
| Maps port 5678 on your host to port 5678 inside the container. This is the default port that n8n runs on. |
| Creates a named volume |
| The image to run. This is the official n8n Docker image from n8n’s private registry. |
The problem?
So I played around with this set up for while and then faced an issue.
I couldn’t use external JavaScript libraries in the code node.
When I dig deep I found that this is because the JavaScript in the code node runs in a sandbox environment and does not allow external libraries by default for security reasons.
If you want to use them you have to enable external libraries.
How to enable external libraries in code node
It’s very simple, you have to set the following environment variable.
NODE_FUNCTION_ALLOW_EXTERNAL
Setting the value to * will allow any library.
NODE_FUNCTION_ALLOW_EXTERNAL=*
You can enable only the ones you want by giving the name or list of names separated by commas.
NODE_FUNCTION_ALLOW_EXTERNAL=cheerio
How set the environment variable
If you are running n8n with the docker run command, you can add the option -e
to set the variable.
-e NODE_FUNCTION_ALLOW_EXTERNAL=*
docker run -it --rm --name n8n -p 5678:5678 -v n8n_data:/home/node/.n8n -e NODE_FUNCTION_ALLOW_EXTERNAL=* docker.n8n.io/n8nio/n8n
Using docker compose to run n8n
I don’t use this docker run command anymore.
I created a docker compose file and a .env file to store all the information in the run command.
Docker compose file
Here’s my docker compose file. You can set the environment variable in here itself.
version: '3.9'
services:
n8n:
image: n8nio/n8n:latest
container_name: n8n
ports:
- "5678:5678" # Expose n8n on port 5678
restart: unless-stopped
env_file:
- .env # Load environment variables from the .env file
volumes:
- F:/n8n-data:/home/node/.n8n # Map the host path for persistent data
# environment:
# - NODE_FUNCTION_ALLOW_EXTERNAL # Allow external modules in Function node
# command: ["start", "--tunnel"] # Start n8n with tunnel mode
Here’s my .env file, you can add all the environment variables here.
GENERIC_TIMEZONE=Australia/Brisbane
NODE_FUNCTION_ALLOW_EXTERNAL=*
So now I can run the following commands to bring n8n container up or down.
docker compose up -d
docker compose down
Checkout this video where I walk you through all of the above steps.
If you want to learn docker, checkout the following post: https://javacodehouse.com/blog/docker-tutorial/