Import path module

I try to do manipulation path, but n8n seem not found Path module (i try with/without import)

i import it :

const path = require('path');

ERROR: Cannot find module ‘path’ [Line 1]

Is a node.js built-in module, and i don’t understand why i cannot do i simple :
path.dirname(item.json.path) in function node.

maybe I’m getting it wrong, I didn’t see anything on the doc.


ps: here is code on function node :

dr_asset_path = "O:/assets/"
for (item of items) {
  splitted_path = item.json.path.split("/From_PATH/FOLD_asset/")[1]
  item.json.path_server = dr_asset_path.concat(splitted_path)
  // item.json.dirname = path.dirname(item.json.path)

return items;

Hi @Jeremy_Bepoix, you’d need to specifically allow modules to be imported in n8n’s Function/FunctionItem nodes. The required environment variables are NODE_FUNCTION_ALLOW_BUILTIN and NODE_FUNCTION_ALLOW_EXTERNAL.

Ok, thank you
i’ve just set en var and reboot service and i’ve got same issue.

windows env var screenshot :

n8n :

Hm, I just tried this and this module is working fine for me when running n8n like docker run -it --rm -p 5678:5678 -e NODE_FUNCTION_ALLOW_BUILTIN=* --name n8n -v ~/.n8n:/home/node/.n8n n8nio/n8n:0.192.2:

How have you deployed n8n?

Okay, works fine.
I had not restarted the terminal after changing the VAR, sorry for the noise.

thank you again

1 Like

Awesome! I’m glad to hear this worked in the end, thanks so much for confirming!