Cloudron makes it easy to run web apps like WordPress, Nextcloud, GitLab on your server. Find out more or install now.


Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Bookmarks
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

Cloudron Forum

Apps | Demo | Docs | Install
  1. Cloudron Forum
  2. N8N
  3. How to install npm modules?

How to install npm modules?

Scheduled Pinned Locked Moved Solved N8N
26 Posts 6 Posters 3.9k Views 6 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • girishG girish

    Generally, I look into the modules a bit before including them into the package. For example, https://www.npmjs.com/package/generate-password hasn't been updated for 2 years. Is this safe anymore (given that it's generating passwords).

    @shrey More often than not, it is best to include library functions in your code then use modules. We are a node shop ourselves, and we have actually removed almost 50% of the modules we used to depend on the past and just include them in our code base itself. The smaller simple library function style modules are in my experience very risky.

    K Offline
    K Offline
    kastiell93
    wrote on last edited by
    #16

    @girish Hi! Can you add the firebase-admin package to n8n?

    1 Reply Last reply
    0
    • nebulonN Away
      nebulonN Away
      nebulon
      Staff
      wrote on last edited by
      #17

      Added now

      1 Reply Last reply
      0
      • E Offline
        E Offline
        ebauger
        wrote on last edited by
        #18

        npm install stripe?

        1 Reply Last reply
        0
        • E Offline
          E Offline
          ebauger
          wrote on last edited by ebauger
          #19

          Hi @nebulon!

          What if we can install custom npm module from this line export NODE_FUNCTION_ALLOW_EXTERNAL=module1,modulel2,moduleN+1
          in /app/data/env.sh

          Here the modified Dockerfile I propose:

          FROM cloudron/base:4.2.0@sha256:46da2fffb36353ef714f97ae8e962bd2c212ca091108d768ba473078319a47f4
          
          RUN mkdir -p /app/pkg /app/code
          WORKDIR /app/code
          
          RUN apt-get update && \
              apt-get -y install graphicsmagick recutils asciidoctor pandoc musl && \
              rm -rf /var/cache/apt /var/lib/apt/lists
          
          RUN ln -s /usr/lib/x86_64-linux-musl/libc.so /lib/libc.musl-x86_64.so.1
          
          ARG N8N_VERSION=1.25.1
          
          # Add a script to install npm packages from env.sh
          COPY install_packages_from_env.sh /app/pkg/
          RUN chmod +x /app/pkg/install_packages_from_env.sh
          
          # n8n. handlebars and jsonata are just helpful modules that user can enable
          RUN npm install n8n@${N8N_VERSION}  && \
              npm install handlebars@4.7.7 jsonata@2.0.2 marked@4.3.0 bwip-js@3.3.0 ajv-formats@2.1.1 odoo-xmlrpc@1.0.8 firebase-admin@11.10.1
          
          # install custom npm modules from the env.sh on the NODE_FUNCTION_ALLOW_EXTERNAL
          RUN /app/pkg/install_packages_from_env.sh /app/data/env.sh
          
          RUN rm -rf /app/code/node_modules/n8n/dist/public && ln -s /run/public /app/code/node_modules/n8n/dist/public
          
          ENV N8N_USER_FOLDER="/app/data/user"
          ENV N8N_CONFIG_FILES="/app/data/configs/default.json"
          ENV N8N_CUSTOM_EXTENSIONS="/app/data/custom-extensions"
          
          ENV PATH=/app/code/node_modules/.bin:$PATH
          
          COPY start.sh env.sh.template /app/pkg/
          
          CMD [ "/app/pkg/start.sh" ]
          

          And here's an example of what the install_packages_from_env.sh script might look like:

          #!/bin/bash
          
          # Script to install npm packages from env.sh
          
          ENV_FILE=$1
          
          if [ -f "$ENV_FILE" ]; then
              # Extract the line with NODE_FUNCTION_ALLOW_EXTERNAL and check if it's not commented
              PACKAGES_LINE=$(grep -E '^export NODE_FUNCTION_ALLOW_EXTERNAL=' $ENV_FILE)
          
              if [ ! -z "$PACKAGES_LINE" ]; then
                  # Remove 'export ' prefix
                  PACKAGES=$(echo $PACKAGES_LINE | sed 's/export NODE_FUNCTION_ALLOW_EXTERNAL=//')
          
                  # Split the packages and install them if not already present
                  IFS=',' read -ra ADDR <<< "$PACKAGES"
                  for package in "${ADDR[@]}"; do
                      if [ ! -d "./node_modules/$package" ]; then
                          echo "Installing $package..."
                          npm install $package
                      else
                          echo "$package is already installed."
                      fi
                  done
              else
                  echo "No packages to install or line is commented out with #."
              fi
          else
              echo "env.sh file not found"
          fi
          

          On (re)start of n8n, the npm modules should installed.

          What do you think?

          1 Reply Last reply
          1
          • nebulonN Away
            nebulonN Away
            nebulon
            Staff
            wrote on last edited by
            #20

            I am not sure I follow the proposal 100% but the main root cause of not being able to install other node_modules is actually that apps run in a read-only filesystem. So I don't see how such a script would fix this problem, but maybe I miss a point in your proposal.

            E 1 Reply Last reply
            0
            • nebulonN nebulon

              I am not sure I follow the proposal 100% but the main root cause of not being able to install other node_modules is actually that apps run in a read-only filesystem. So I don't see how such a script would fix this problem, but maybe I miss a point in your proposal.

              E Offline
              E Offline
              ebauger
              wrote on last edited by
              #21

              @nebulon my proposal is to install the modules when we build the image from the Dockerfile. I open to any other solution.

              The modules installed will be on the read-only filesystem. See the Diff from this source

              ...
              # Add a script to install npm packages from env.sh
              COPY install_packages_from_env.sh /app/pkg/
              RUN chmod +x /app/pkg/install_packages_from_env.sh
              ...
              # install custom npm modules from the env.sh on the NODE_FUNCTION_ALLOW_EXTERNAL
              RUN /app/pkg/install_packages_from_env.sh /app/data/env.sh
              ...
              
              BrutalBirdieB 1 Reply Last reply
              0
              • E ebauger

                @nebulon my proposal is to install the modules when we build the image from the Dockerfile. I open to any other solution.

                The modules installed will be on the read-only filesystem. See the Diff from this source

                ...
                # Add a script to install npm packages from env.sh
                COPY install_packages_from_env.sh /app/pkg/
                RUN chmod +x /app/pkg/install_packages_from_env.sh
                ...
                # install custom npm modules from the env.sh on the NODE_FUNCTION_ALLOW_EXTERNAL
                RUN /app/pkg/install_packages_from_env.sh /app/data/env.sh
                ...
                
                BrutalBirdieB Offline
                BrutalBirdieB Offline
                BrutalBirdie
                Partner
                wrote on last edited by
                #22

                @ebauger
                Docker images are build before runtime.
                /app/data does only exist on runtime.
                So the command:

                RUN /app/pkg/install_packages_from_env.sh /app/data/env.sh
                

                will not work.

                But I understand where the intention is.

                Like my work? Consider donating a drink. Cheers!

                1 Reply Last reply
                1
                • girishG Offline
                  girishG Offline
                  girish
                  Staff
                  wrote on last edited by
                  #23

                  Recently, with nodebb we started experimenting with making the node_modules writable (grudgingly). Maybe we can do the same for n8n.

                  S 1 Reply Last reply
                  2
                  • girishG girish

                    Recently, with nodebb we started experimenting with making the node_modules writable (grudgingly). Maybe we can do the same for n8n.

                    S Offline
                    S Offline
                    shrey
                    wrote on last edited by
                    #24

                    @girish Certainly support this effort!

                    1 Reply Last reply
                    0
                    • girishG Offline
                      girishG Offline
                      girish
                      Staff
                      wrote on last edited by
                      #25

                      This is implemented in https://docs.cloudron.io/apps/n8n/#custom-node-modules .

                      @shrey let me know if you get a chance to test it.

                      S 1 Reply Last reply
                      3
                      • girishG girish has marked this topic as solved on
                      • girishG girish

                        This is implemented in https://docs.cloudron.io/apps/n8n/#custom-node-modules .

                        @shrey let me know if you get a chance to test it.

                        S Offline
                        S Offline
                        shrey
                        wrote on last edited by
                        #26

                        @girish Just tried it. Seems to work alright! 🙂

                        1 Reply Last reply
                        1
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Bookmarks
                        • Search