How is possible to use a library as lodash in function node?

Describe the issue/error/question

I want to use lodash into function module. But I was reading the documentation and it seems that I need to create a configuration file. The problems are that I have no idea about where I must create the file and if it will be usefull to use into the cloud. It are different configurations?

Thank you very much for your time and support.
BR!

Information on your n8n setup

  • n8n version: 0.160.0
  • Database you’re using (default: SQLite): N/A
  • Running n8n with the execution process [own(default), main]: own
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: n8n.cloud and desktop app

Hey @franchogarcia, seeing you use both n8n.cloud and desktop there is good news and bad news here.

The bad news: You can’t use lodash on n8n.cloud straight away. It’s not part of the NODE_FUNCTION_ALLOW_EXTERNAL configuration on n8n.cloud, so running code like var _ = require('lodash'); would fail.

The good news: This is possible on n8n.desktop just like with any other self-hosted n8n instance. For n8n desktop specifically you would need to edit the n8n-desktop.env file inside the .n8n folder of your home directory (so C:\Users\franchogarcia\.n8n\n8n-desktop.env if you are on Windows). This file contains the environment variables used by n8n.cloud. Add a line NODE_FUNCTION_ALLOW_EXTERNAL=lodash to the file (if you already have an entry for NODE_FUNCTION_ALLOW_EXTERNAL in the file, update the existing entry instead). Save the file and restart n8n to apply the changes.

You can now run a workflow like this on n8n.desktop and use lodash in the Function node:

1 Like

Thank you a lot for your support @MutedJam as always!! :slight_smile:
Where is the file if I am in Mac?

I think that would be ~/.n8n/n8n-desktop.env though I don’t have a Mac to confirm this myself. Maybe @Jon as a fellow Mac user can confirm the location of the n8n-desktop.env file there?

Same path :smiley:

The full version would be /Users/username/.n8n/n8n-desktop.env as you may not have an existing entry if you have not touched the file before you can just pop open a terminal and run the below command then restart the n8n app.

echo "NODE_FUNCTION_ALLOW_EXTERNAL=lodash" | tee -a ~/.n8n/n8n-desktop.env >/dev/null
2 Likes

thx a lot @Jon !!
BR!

2 Likes