It would be cool to be allowed to use node modules (native ones, at least) in Function and FunctionItem nodes.
This can be achieved replacing here for this (from vm2 readme):
const vm = new NodeVM({
console: 'inherit',
sandbox: {},
require: {
external: false,
builtin: ['fs', 'https'], // this can also be ['*'] for all modules
root: "./",
mock: {
fs: {
readFileSync() { return 'Nice try!'; }
}
}
}
});
I know it would not be safe so a workaround may be a new node called UnsafeFunction. Or maybe mock every dangerous function.
Hm doing that would kind of defeat the whole purpose why I used vm2 in the first place
Can however understand why you want to do that. What you could do is to just make the change to the node you want (and give it a different name) and then use the ân8n-node-devâ CLI like described here:
It will then build the node and copy it to the ~/.n8n/custom/ folder. Then simply restart n8n and your custom node will be loaded and you can use all the npm modules you want.
I followed your instructions to create a custom node so I could use the âhttpâ module in my functions. I keep on getting the error error TS1003: Identifier expected. when i try to build it.
My custom node code is the default code plus this line after the import statements import * as http from 'http'.
Tried searching the web but couldnât find anything, am I missing something here ?
Please open a new issue. The problem you are having is not related to the Function or FunctionItem-Node. If we do not try our best to keep things on topic it will be very hard for people to find solutions to their problems. Thanks!