How to install npm modules?
-
Having gone through related posts (e.g. https://forum.cloudron.io/post/55351), i couldn't find a way to install npm modules for use within n8n (in the Code node).
What's the latest method to do so?
-
-
@girish Hi.
Could you please add the following npm libraries to n8n:Thanks.
-
Where are those required? Those appear to be very specific. If this is custom code then given the low complexity of those modules, I would suggest to just add the js file from them. Like generate-password is really only https://github.com/brendanashworth/generate-password/blob/master/src/generate.js
-
Hi @nebulon. Thanks for the recommendation.
Although, that's a bit of an odd recommendation. Because, i would like to be able (and also expect) to use the tool (n8n) with pretty much all of its capabilities that are allowed for the self-hosted versions, being able to natively use any compatible npm package being one of them.
@nebulon said in How to install npm modules?:
If this is custom code then given the low complexity of those modules, I would suggest to just add the js file from them.
Also, this isn't very efficient or even feasible as firstly, reusability of code/scripts is not a big thing in n8n. So, the entire script will have to be included in every node, every time it's required. Secondly, that's not the normal way of doing things in n8n.
I was under the impression that this was supposed to be a simple formality (to send a request to include an npm package in the n8n modules) and not really a vetting process. If that's not the policy of Cloudron for the near-future, then kindly let me know.
Thanks.
-
it is a simple change at first, but the more node modules we ship, the higher the chances that it will break if we update and we can't realistically test all this. Mostly this is also due to our experience with how often node_modules become unmaintained, or break compatibility. Like with other loose plugin systems this is becomes an update nightmare very soon, so we are a bit hesitant to add non-essential ones and especially not ones which are solidly maintained upstream.
-
So far this was not possible to implement due to the way npm works and how n8n handles requires. This is actually the only reason why we have this workaround to include essential ones in the package.
There is always a fine line between being able to test updates and maintain packages vs. full customization with code changes by the sysadmin. We usually aim for a middleground where we don't lose the ability to test updates.
-
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.