How to setup external node_modules in hosted version?

I’m running my n8n instance on a self-hosed environment inside DigitalOcean. Inside the code node I would like to use the Mollie Api client to charge payments. From the docs, I understand I should first allow n8n to execute external modules. Below is an outline of steps I took to make this work, however without success.

Log into DigitalOcean, open the console as root

  • export NODE_FUNCTION_ALLOW_EXTERNAL=*
  • cd n8n && npm init -y && npm i -S @mollie/api-client
  • docker-compose down
  • docker-compuse up -d

While executing the code below inside the node, I get the not found error: ERROR: Cannot find module '@mollie/api-client' [line 1, for item 0]

const { createMollieClient } = require('@mollie/api-client')
console.log(createMollieClient)

Does anyone know how to make this work?

Hi @mdings, this looks like you have installed the npm module on your host machine rather than inside your n8n docker container. So, if you are using docker to run n8n and you would like to install additional npm modules you’d need to create a custom docker image for n8n that includes the npm packages you’re looking into.

Unfortunately, I don’t have a ready-to-run example at the moment (our docker images have changed a lot recently), but n8n/docker/images/n8n-custom at master · n8n-io/n8n (github.com) should be a solid base for your customization.

Thanks, I’ll look into that. I’m not that familiar with docker & docker-compose, just followed the docs on the website to get it up and running. So if you have more direct examples of how to install node/npm and dependencies inside a docker container, I’d be happy to hear those!

Tbf, I would suggest you avoid adding node modules only to interact with a REST API like this one. It’ll mean you’d have to maintain your own Dockerfile continuously in order to reflect any changes to n8n, which can be a pain.

Perhaps you might instead want to consider simply using the existing HTTP Request node to interact with the API in question? Looking at the example from the documentation it can be as simple as making a GET request to a URL such as https://api.mollie.com/v2/payments/tr_WDqYK6vllg with an Authorization header with a value of Bearer test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM. That’s something the HTTP Request node should handle nicely.

1 Like

That’s an excellent consideration. I’ve been using the SDK in my own Netlify webhooks but wanted to consolidate all logic into one place. I guess I overlooked the possibility to use the direct endpoint there :grinning:
All go for that option, thanks for the pointers @MutedJam!

1 Like

No worries! If you hit any errors or limitations give me a shout :slight_smile:

Btw can I use multiple entry points inside a workflow?

In the example below I have a cron job that takes all payments that should be handled. Inside the HTTP request there is a parameter called webhook URL which is called by the payment provider with the status of the payment.
That webhook URL should then handle any statuses from the payment, for example send a confirmation message whenever the payment succeeded. It would be nice to have those entries inside the same workflow since they’re closely related. While testing I need to disable the webhook otherwise n8n will wait for the hook to be called, while the upper flow with the cron entry should be run. Will this work when moving to “production”?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.