NPM Package Management for Self-Hosted Environments - n8n Workflow

Automate installing and validating required NPM packages (like axios or cheerio) within your self-hosted n8n environment using a resilient n8n workflow. Perfect for Docker deployments.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Markdown-formatted:
Users running self-hosted n8n instances (especially Docker) who require custom NPM libraries.
Technical users who write custom JavaScript in Function n8n nodes or utilize third-party modules.
DevOps specialists seeking reliable environment maintenance for their n8n instance.
Developers looking for resilient n8n templates to standardize dependency deployment.

Overview

Maintaining consistency in a self-hosted n8n environment, particularly when custom libraries are needed for advanced scripting in Function nodes, can be challenging. Container restarts often reset the environment, removing dependencies. This powerful n8n workflow solves this by automatically checking for and installing essential NPM packages (e.g., axios, cheerio, node-fetch) whenever the n8n instance starts, on a scheduled basis, or via manual command. By utilizing the Execute Command n8n node, this n8n automation ensures that your environment is always ready for complex operations, improving the reliability of all your other n8n templates and custom solutions.

How it Works

Markdown-formatted:
This comprehensive n8n workflow is designed for maximum operational resilience, featuring three independent n8n trigger nodes.


  1. Multiple Triggers: The n8n workflow can be initiated manually (triggermanual), periodically (triggerschedule), or critically, when the n8n instance initializes (triggerinstance with the init event). This ensures package availability even after a server reboot.

  2. Define Libraries: The first Set n8n node, librariesset, defines a comma-separated string containing all required packages (e.g., axios,cheerio,node-fetch).

  3. Data Preparation: The subsequent Set n8n node, librariesarray, converts this string into a processable JSON array using a simple split expression.

  4. Itemization: The Split Out n8n node, librariessplit, separates the array so that each package name is handled as an individual item, ensuring the installation process is atomic for every library.

  5. Execution and Installation: The core logic resides in the Execute Command n8n node, libraryinstall. This n8n node executes a Bash script that performs three critical tasks for the given library:

a. Checks if the package directory exists in the standard n8n nodemodules path.
b. If the package is missing, it executes npm install "$LIBRARY_NAME".
c. It verifies the installation, ensuring successful dependency loading for the n8n environment.

Installation Guide

Markdown-formatted:


  1. Import the n8n Workflow: Copy the provided JSON data and paste it directly into your n8n instance via the Workflows section (New -> Import from JSON).

  2. Verify Configuration: No external credentials are required, as this n8n workflow uses core nodes.

  3. Customize Dependencies: Navigate to the librariesset n8n node and update the value in the 'libraries' field to include all the specific NPM packages required by your custom n8n templates and Function nodes.

  4. Set Triggers: Enable the desired n8n trigger nodes. For maximum stability, ensure the triggerinstance (Init event) is active. The trigger_schedule can be configured for daily or weekly checks if required.

  5. Activate: Save and activate the n8n workflow. The packages will now be managed automatically.

Node Details

Markdown-formatted:
Manual Trigger / Schedule Trigger / n8n Trigger: These three n8n trigger nodes provide flexible initiation points (manual run, scheduled check, and instance initialization) for the dependency management process.
Set (librariesset): Function: Holds the initial list of required NPM packages as a comma-separated string (axios,cheerio,node-fetch). This is the primary configuration point for defining dependencies in this n8n workflow.
Set (librariesarray): Function: Transforms the comma-separated string into a JSON array using the expression {{ $json.libraries.split(",") }}, preparing the data for iteration.
Split Out (librariessplit): Function: Splits the array so that each package name becomes a distinct item, allowing the subsequent n8n node to process each installation request independently.


  • Execute Command (libraryinstall): Function: The central n8n node that executes the Bash script. It checks for the existence of the package directory and runs npm install only if the package is missing. This process ensures necessary libraries are consistently available in the n8n environment.

Related n8n Workflows

Free

Nodes: 6 Nodes
Updated: December 26 2025
View all
Created by

Featured*