Need Help to access the nodejs in function node

Hello n8nians!

I was trying to get the access of the nodeJS built in module in the function node, i was specifically
trying to get the following one.

const fs = require('fs')

and the function node returns the error as : 
VMError: Cannot find module 'fs'
    at LegacyResolver.resolveFull (/usr/lib/node_modules/n8n/node_modules/vm2/lib/resolver.js:110:9)
    at LegacyResolver.resolveFull (/usr/lib/node_modules/n8n/node_modules/vm2/lib/resolver.js:316:16)
    at LegacyResolver.resolveFull (/usr/lib/node_modules/n8n/node_modules/vm2/lib/resolver-compat.js:100:17)
    at LegacyResolver.resolve (/usr/lib/node_modules/n8n/node_modules/vm2/lib/resolver.js:105:15)
    at VM2 Wrapper.apply (/usr/lib/node_modules/n8n/node_modules/vm2/lib/bridge.js:485:11)
    at requireImpl (/usr/lib/node_modules/n8n/node_modules/vm2/lib/setup-node-sandbox.js:84:28)
    at require (/usr/lib/node_modules/n8n/node_modules/vm2/lib/setup-node-sandbox.js:165:10)
    at /usr/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Function:40:10
    at /usr/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Function:106:2
    at VM2 Wrapper.apply (/usr/lib/node_modules/n8n/node_modules/vm2/lib/bridge.js:485:11)

   can i access nodejs built in module in function node?
   
   Thanks

## Information on your n8n setup
- **n8n version: 0.189.1 **
- **Database you're using (default: SQLite): sqlite**
- **Running n8n with the execution process [own(default), main]:**
- **Running n8n via [Docker, npm, n8n.cloud, desktop app]: npm**

Hey @msm,

Welcome to the community :tada:

Have you set NODE_FUNCTION_ALLOW_BUILTIN or NODE_FUNCTION_ALLOW_EXTERNAL to include fs?

Hello Jon

Thanks for the reply.
I have set the NODE_FUNCTION_ALLOW_BUILTIN=fs as a system environment variables, and i am using ubuntu 20.04 as os.

Hey @msm,

Can you share the command you use to run n8n? I can give it a go and see if I can reproduce the same issue.

Hey Jon

I use the command n8n start to run n8n.

Hey @msm,

Did you run the export command just before that?

Thanks Jon

Now i can use the node module in the function node.

Best
msm

1 Like