How to uses the Default Node Javascript libraries like Crypto?

Describe the problem/error/question

We are currently working on a project that utilizes n8n, and we need to implement data encryption using the aes-256-gcm algorithm. To achieve this, we would like to use the built-in Node.js crypto library, but we have noticed that it is not available in n8n’s code nodes.

We understand that some Node.js libraries may require activation or specific configurations to be used within n8n workflows. Could you provide guidance on whether there is a way to enable the crypto library for code nodes?

I was reading the n8n documentation and came across this section:

“If you use n8n Cloud, you can’t import external npm modules. However, n8n makes two modules available for you:”

  • crypto (Node.js module)
  • moment (npm package)

What is the error message (if any)?

“Cannot find module ‘crypto’ or its corresponding type declarations.”

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • 1.79.3
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • n8n Cloud
  • Operating system:
  • Windows
1 Like

Hey @willhg72 Did you set it up like this?

const crypto = require('crypto');

For me, this works on the same version

1 Like

Hey jjksr!,

Thank you! Yes, I did that, but I can still see the red squiggly line under “crypto.”

Best,
Will

Hey @willhg72

The Red error squiggly line doesn’t matter for external modules, the code node doesn’t have full access to all of the modules from the front end so it thinks there is an issue but as long as the node runs then you execute it all is good.

In the future we plan to remove the check in the editor for external modules which will resolve the ui issue.

1 Like

Hey Jon,

Oh, I see! I thought it was an error, but I tested the code, and the information was successfully encrypted without any issues.

Thanks for the quick support!

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.