Skip to content

在代码节点中启用模块#

¥Enable modules in Code node

出于安全考虑,代码节点限制了模块的导入。可以通过设置以下环境变量来解除内置模块和外部模块的此限制:

¥For security reasons, the Code node restricts importing modules. It's possible to lift that restriction for built-in and external modules by setting the following environment variables:

  • NODE_FUNCTION_ALLOW_BUILTIN:内置模块:

¥NODE_FUNCTION_ALLOW_BUILTIN: For built-in modules

  • NODE_FUNCTION_ALLOW_EXTERNAL:对于来自 n8n/node_modules 目录的外部模块。如果未设置环境变量,则禁用外部模块支持。

¥NODE_FUNCTION_ALLOW_EXTERNAL: For external modules sourced from n8n/node_modules directory. External module support is disabled when an environment variable isn't set.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Allows usage of all builtin modules
export NODE_FUNCTION_ALLOW_BUILTIN=*

# Allows usage of only crypto
export NODE_FUNCTION_ALLOW_BUILTIN=crypto

# Allows usage of only crypto and fs
export NODE_FUNCTION_ALLOW_BUILTIN=crypto,fs

# Allow usage of external npm modules.
export NODE_FUNCTION_ALLOW_EXTERNAL=moment,lodash

If using Task Runners

如果 n8n 实例使用 任务运行器 配置,请将环境变量添加到任务运行器,而不是添加到主 n8n 节点。

¥If n8n instance is setup with Task Runners, add the environment variables to the Task Runners instead to the main n8n node.

有关这些变量的更多信息,请参阅 环境变量参考

¥Refer to Environment variables reference for more information on these variables.