Dexter Langford
Dexter Langford

If you’re using n8n on a DigitalOcean droplet and want to unlock more features inside the Code node, like using powerful tools such as moment or lodash, this guide is for you — even if you’re not a developer!

Why You’re Doing This

Sometimes when you’re building workflows in n8n, you want to use external JavaScript tools like date manipulation (moment) or array tools (lodash). But n8n won’t allow it unless you tell it it’s okay.

You do that by adding a “secret note” (called an environment variable) to your n8n setup.

What You’ll Need

  • A DigitalOcean account with your n8n Droplet running.
  • About 10 minutes.
  • The ability to copy & paste!

Step 1: Access Your Droplet

  1. Go to your DigitalOcean dashboard.
  2. Click on your Droplet (it probably looks like this):
  3. Click the three dots and then click Access console.

Step 2: Open the Setup File

  1. You’ll now be inside your n8n server terminal.
  2. Type this to open the n8n setup file:
nano /opt/n8n-docker-caddy/docker-compose.yml

It should look like this:

Step 3: Add the Environment Variable

Find the section that starts with:

environment:

Add this line just below it (or update if already there):

- NODE_FUNCTION_ALLOW_EXTERNAL=moment,lodash

You can allow other tools too by separating them with commas (no spaces!).

Your full block will look something like:

environment:
  - NODE_FUNCTION_ALLOW_EXTERNAL=moment,lodash
  - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
  - N8N_PORT=5678
  - N8N_PROTOCOL=https
  ...

Step 4: Save and Exit

If you’re using nano (a text editor), press:

  • CTRL + O (to save)
  • Hit Enter (to confirm)
  • Then CTRL + X (to exit)

Step 5: Restart n8n

Now apply your changes by running these commands:

cd /opt/n8n-docker-caddy
docker compose pull
docker compose up -d

That’s it! 🎉 Your n8n now allows you to use external modules like moment in the Code node.


Leave a Reply

Your email address will not be published. Required fields are marked *