Code Node and require question

Describe the problem/error/question

I experimented with using require from a code node and it appears that to use require for a lib that is not under node_modules, we cannot use relative paths.

Essentially this works: const myLib = “/dev4/n8n/fcts/myFct”;
But this DOES NOT: const myLib = “./fcts/myFct”;
even though the current dir is /dev4/n8n (confirmed by using cwd() command)

Is this indeed intended? Asking as it is not intuitive - I suppose this may be done for security reasons?

Information on your n8n setup

  • n8n version: 1.80.5
  • Database (default: SQLite): default
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • **Running n8n via: local install **
  • **Operating system: Windows 11 **

I suggest you always uses the absolute path.

Sure but can someone from n8n development confirms that’s indeed intended and explain why.
With such information we could update the doc that does not say anything for such an important topic.

Thanks

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