Skip to content

在代码节点中启用模块

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

  • :对于内置模块
  • :适用于来自 n8n/node_modules 目录的外部模块。未设置环境变量时,外部模块支持将被禁用。

 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
Refer to Environment variables reference for more information on these variables.