I’m working on an n8n custom node for my company. Right now, I have two action nodes (authenticate and upload file) that show up when I search for the company node. But they appear as separate options in a dropdown menu.
What I’m aiming for is a structure like the S3 node, where there’s one main node with different actions inside it. I don’t want separate core nodes for each action because that doesn’t make sense for my use case.
I’ve set up my main.node.ts file with authentication and file upload operations, and my package.json includes paths to these node files. But I can’t figure out how to nest them under a single main node.
I tried creating separate auth.node.ts and upload.node.ts files and adding them to the package.json, but that just created two independent core nodes.
Any ideas on how to achieve this nested structure in n8n? I’m stuck and could use some guidance!
I’ve encountered a similar challenge with n8n custom nodes. The key is to use the ‘resource’ and ‘operation’ properties within your main.node.ts file. This allows you to create a dropdown for different actions.
In your execute function, you can then use a switch statement to handle each operation. Something like:
switch (resource) {
case 'auth':
// Authentication logic
break;
case 'upload':
// File upload logic
break;
}
This approach keeps everything under one main node while allowing multiple actions. It’s cleaner and more intuitive for users. Just make sure to properly define the properties for each action in your node definition.
hey sophia, maybe combine all ur actions in main.node.ts using the operation property for a dropdown. then in the excute function, use conditionals to run the right action. hope this clears things up!
As someone who’s worked extensively with n8n custom nodes, I can offer some insights on creating that nested structure you’re after. The key is to utilize the ‘resource’ and ‘operation’ properties within your main.node.ts file. This approach allows you to create a dropdown menu for different actions, all under one main node.
In your execute function, you’ll want to use a switch statement to handle each operation. It might look something like this:
switch (operation) {
case 'authenticate':
// Your authentication logic here
break;
case 'uploadFile':
// Your file upload logic here
break;
}
This method keeps everything under one main node while allowing for multiple actions. It’s a cleaner and more intuitive setup for users. Just ensure you properly define the properties for each action in your node definition.
One thing to keep in mind: you’ll need to carefully consider how to handle shared logic or data between operations. For instance, if the upload operation requires authentication, you might need to implement a way to check and perform authentication first.
Hope this helps point you in the right direction, Sophia!