How do I set ENV Variables in n8n cloud?

I use the cloud instance of n8n and want to use moment.js. Can you let me know how I can enable external modules in the cloud instance?

Hi @Bala_Panneerselvam, I am afraid it’s currently not possible to import external Node.js modules in n8n.cloud (as it will always run the “vanilla” version of n8n) or set environment variables.

That said, you can execute any JavaScript code through the Function (or Function Item) node and this would include the Moment.js code. Here’s an example but this includes the really bad eval() method which should always be avoided (so best to see this as a proof of concept rather than a suggestion):

Going forward, you might want to leave a vote at Externally hosted nodes which covers externally hosted code.

Appreciate the response, thanks.

1 Like

To follow up on this: We’re currently checking whether we can open up the use of Moment.js specifically on n8n.cloud for users and will make sure to keep you updated on the progress :slight_smile:

2 Likes

Do you have any update on this matter?

have you found a solution? Can you share please? Many thanks

Hey @Ze_Governo,

It looks like you can use Moment.js with cloud, As a quick test I just ran the function below.

const moment = require('moment')
const date = moment().format("Do MMMM YYYY");

for (item of items) {
  item.json.myNewField = date;
}
return items;

This resulted in an output of
image

2 Likes

Thanks for the example @Jon, and apologies for not updating this thread @Ze_Governo! Indeed, moment.js is now available on n8n.cloud without requiring additional configuration.

1 Like

Many thanks @MutedJam and @Jon.

1 Like