Pre-requisite

npm
Node.js 16

You will need dependency above on your Linux system, install by running command below

cd /tmp
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
source ~/.profile
nvm install 16
sudo apt install npm -y

Installation

  1. Create a new directory
sudo mkdir /root/.n8n/nodes/external/node_modules
  • Install npm modules under /root/.n8n/nodes/external/node_modules
  • Stop any existing n8n docker images
  • sudo docker stop n8n
  • Mount modules one by one to n8n docker image, replace [MODULE NAME] with the package name
  • Please ensure you include dependency for the modules as well, otherwise you will not be able to use the it in N8N

    docker run -d --rm \
        --name n8n \
        -p 5678:5678 \
        -v ~/.n8n:/home/node/.n8n \
        -e GENERIC_TIMEZONE="America/New_York" \
        -e TZ="America/New_York" \
        -e NODE_FUNCTION_ALLOW_BUILTIN=* \
        -e NODE_FUNCTION_ALLOW_EXTERNAL=* \
        -v /root/.n8n/nodes/node_modules/[MODULE NAME]:/usr/local/lib/node_modules/[MODULE NAME] \
        n8nio/n8n:latest

    For example, I want to use node-fetch in n8n function node, these are the steps I took

    https://www.npmjs.com/package/node-fetch

    1. Go to directory and install
    cd /root/.n8n/nodes/node_modules
    npm i node-fetch
  • Mount node-fetch and its dependencies
  • docker run -d --rm \
        --name n8n \
        -p 5678:5678 \
        -v ~/.n8n:/home/node/.n8n \
        -e GENERIC_TIMEZONE="America/New_York" \
        -e TZ="America/New_York" \
        -e NODE_FUNCTION_ALLOW_BUILTIN=* \
        -e NODE_FUNCTION_ALLOW_EXTERNAL=* \
        -v /root/.n8n/nodes/external/node_modules/data-uri-to-buffer:/usr/local/lib/node_modules/data-uri-to-buffer \
        -v /root/.n8n/nodes/external/node_modules/fetch-blob:/usr/local/lib/node_modules/fetch-blob \
        -v /root/.n8n/nodes/external/node_modules/formdata-polyfill:/usr/local/lib/node_modules/formdata-polyfill \
        -v /root/.n8n/nodes/external/node_modules/node-domexception:/usr/local/lib/node_modules/node-domexception \
        -v /root/.n8n/nodes/external/node_modules/node-fetch:/usr/local/lib/node_modules/node-fetch \
        -v /root/.n8n/nodes/external/node_modules/web-streams-polyfill:/usr/local/lib/node_modules/web-streams-polyfill \
        n8nio/n8n:latest