Require modules in function and functionitem

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 :wink:

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.