How to set up date-fnx


I would like to be able to use date-fns in function nodes. I added the following line in docker-compose.yml:


(moment,lodash was before)
Not sure if feiertagejs is required, but I found in some topic and I added this.
Like here I rebuild docker via

docker-compose stop && docker-compose up --force-recreate --build -d && docker image prune -f

I wrote this function to check

const moment = require("date-fns")

console.log(format(new Date(), "'Today is a' eeee"))

But result is

Before rebuild, I had error sth like that date-fns cannot be used in VM

Thanks in advance!

Hey @Shirobachi,

So in that thread you found there is an important part, If you look at the compose file they are including the node modules from the host machine and loading it in the container.

      - /root/node_modules/sugar-core:/usr/local/lib/node_modules/sugar-core
      - /root/node_modules/sugar-date:/usr/local/lib/node_modules/sugar-date
      - /root/node_modules/moment:/usr/local/lib/node_modules/moment

If you were to install the node module you want in a similar way on your Docker host you would be able to do the same thing to load the modules.

The other option is to build your own docker container and in your dockerfile had a section to install the module with npm, I have not tried to do it with a command in the normal image though so you could try that and see what happens.

1 Like

Oh, that’ll work for me, but I had hope it’s easier, thanks a lot!

BTW, I got it, do you think that count data-fns (or other data lib) be added to n8n since even momentJS say don’t use me?

Ref: Moment.js | Docs

1 Like

Mounts would be one way, creating a new image to add the libraries would be another. It’s very simple with compose too

Thanks for this massage, I appreciate that.
TBH, I do not feel confident with docker, so it’s not super simple for me :smiley:

Compose you mean add voluming with lib? Just curious, I use now date-utils if someone need :wink:

1 Like

Together with docker-compose.yml I have a myn8n directory with this Dockerfile

FROM n8nio/n8n

RUN npm_config_user=root npm install -g date-fns date-fns-tz

and added build: myn8n to the n8n service definition


I am I right that you clone repo? I would like to avoid it and work on official image instead of build mine

Not at all. It’s creating another image layer on top of the official n8n. It’s one of the core docker features

1 Like