Skip to content

Instantly share code, notes, and snippets.

@jimmyadaro
Created March 22, 2025 15:01
Show Gist options
  • Save jimmyadaro/c557d11f78e4593687db30b60d1c2b72 to your computer and use it in GitHub Desktop.
Save jimmyadaro/c557d11f78e4593687db30b60d1c2b72 to your computer and use it in GitHub Desktop.
Use npm packages inside n8n (Docker)

Use npm packages inside n8n

Their docs and forums suck to be specific about this.

Install specific packages inside the n8n Docker container and then use it in its nodes:

# Use the official n8n image as the base
FROM n8nio/n8n:1.82.4

# Switch to root user to install dependencies
USER root

# Install the npm packages globally so they're accessible to n8n
RUN npm install -g axios dotenv

# Set environment variables for n8n nodes
# @link: https://docs.n8n.io/hosting/configuration/configuration-examples/modules-in-code-node/
ENV NODE_FUNCTION_ALLOW_BUILTIN=*

# Comma separated list of npm packages to use inside n8n
ENV NODE_FUNCTION_ALLOW_EXTERNAL=axios,dotenv

# Switch back to the n8n default user
USER node

# Run n8n using the default entrypoint sh file
ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"]

Inside a "Code" node in n8n try this (use a real URL):

const axios = require('axios');

async function fetchData() {
  const response = await axios.get('https://api.yourdomain.com/ping');
  return [{ json: response.data }];
}

return fetchData();

It should return the data and throw no error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment