How to structure an n8n custom node with multiple actions under one main node?

I’m trying to create 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 want is a single main node that contains these actions, similar to the structure of the S3 node. I’ve attempted to set up my main.node.ts file with an Operation property that includes both actions, but it doesn’t achieve the desired nested structure.

Below is a snippet of my current main.node.ts configuration:

export class CompanyNode implements INodeType {
  description: INodeTypeDescription = {
    displayName: 'CompanyActions',
    name: 'companyActions',
    properties: [
      {
        displayName: 'Action',
        name: 'action',
        type: 'options',
        options: [
          { name: 'Authenticate', value: 'auth' },
          { name: 'Upload File', value: 'upload' }
        ],
        default: 'auth'
      }
      // ... other properties for each action
    ]
  };
}

I’ve also experimented with creating separate files for each action, but that ended up producing two core nodes instead. Any suggestions on how to achieve a main node structure that houses both actions?

I’ve been there, mate. Structuring a custom node with multiple actions can be a bit tricky. Here’s what worked for me:

First, keep your main.node.ts file as the entry point. Instead of defining separate nodes, use it to create a single node with multiple operations.

In your execute function, use a switch statement based on the selected action. For example:

switch (this.getNodeParameter(‘action’, 0)) {
case ‘auth’:
return await handleAuth(this);
case ‘upload’:
return await handleUpload(this);
}

I organized the code by creating separate files for each action (handleAuth.ts and handleUpload.ts) to keep things clear and maintainable. Don’t forget to update your package.json to include all the relevant file paths. This method should help you achieve the desired nested structure for your custom node. Good luck!

I’ve worked with n8n custom nodes before, and here’s what I found effective for structuring multiple actions under one main node:

In your main.node.ts, keep the structure you have with the ‘Action’ property. The key is in the execute function. Implement a switch statement there to handle different actions:

async execute(this: IExecuteFunctions): Promise<INodeExecutionData> {
const action = this.getNodeParameter(‘action’, 0) as string;
switch (action) {
case ‘auth’:
return await this.handleAuth();
case ‘upload’:
return await this.handleUpload();
}
}

Then, create separate methods (handleAuth, handleUpload) within the same class to keep your code organized. This approach maintains a single node while allowing multiple actions, similar to the S3 node structure you mentioned.

Remember to update your package.json to include the correct file paths. This setup should give you the nested structure you’re aiming for.

hey, i had a similar issue. try using a switch statement in ur execute function to handle diff actions. smth like:

switch (action) {
case ‘auth’:
// auth logic
break;
case ‘upload’:
// upload logic
break;
}

this way u can keep everything under one main node. hope this helps!