Installing the external module

Hello community!

I’m trying to start using the document generator.
Installed using “npm install -g carbone” command.
The example code for the test uses the following variable ( const fs = require(‘fs’) ), which, as far as I understand, should refer to the “fs” dependency built into NodeJs.
It gives me an error (see screenshot).
I understand that there is nothing in this “fs” path, but what should be the correct path in this case?
Or is the problem something else?

Hi @Roket, you’d need to specifically allow the use of modules in n8n. You can allow a built-in module using the NODE_FUNCTION_ALLOW_BUILTIN environment variable and external modules using NODE_FUNCTION_ALLOW_EXTERNAL.

So once you set NODE_FUNCTION_ALLOW_BUILTIN=fs, you should be able to require fs in your Function code.

1 Like

@MutedJam Thanks! Its works.

1 Like

Hi @Roket !

Have you got Carbone working?

When I try to run the same code as in your screenshot (the carbone example code), the function node runs without complaints, but there is no file created. I must be missing something.

I have tried to save a file with fs.writeFileSync, and it can create a file on disk.

I have also tried to put the carbone code in a index.js file and run with “node index.js” inside the n8n container. That works as expected and the result.odt gets created on disk.

Any ideas would be helpful :slight_smile:

Do I have to wrap this into a promise, and if yes, can someone show me the correct syntax for doing this?

Hey @Areip !
I haven’t used carbone in a long time.
I can’t comment on your issue.
Perhaps someone more experienced in the community can help?