Using moment in n8n cloud

Hi there,

I’m trying to do something like this in n8n: date: moment(w.dt * 1000).format("YYYY-MM-DD"), (w is from the input and dt is a unix timestamp

I found this

But I’m getting an error saying:

VMError: Access denied to require 'moment'
    at _require (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/sandbox.js:303:28)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes:1:113
    at Object.<anonymous> (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes:29:2)
    at (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/main.js:1121:29)
    at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Function.node.js:65:31)
    at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/src/Workflow.js:492:37)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/src/WorkflowExecute.js:395:62
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

Is it possible to access something like moment in a function node?

Hey @commandodev!

It is currently not possible to import libraries in the Function node in n8n cloud. However, you can use the Date & Time node to change the format.

Thanks @harshil1712. The date is in some nested data that I need to fiddle with anyway. In the end I just used a substring of toISO :slight_smile:


Yes, that’s another way of doing it :muscle:

I happy your problem is resolved!

1 Like