Extending functionality of a core node - contributions best practices

Describe the problem/error/question

I have a simple usecase not supported by the Google Sheets node: get the list of sheets in a document.

I’ve created a new node, and that’s simple enough following the custom node recipe. However, it would be a nice contribution to the core and I could easily patch it into the GoogleSheetsV2 node.

However… it seems the maintainers are slow to incorporate contributions of this sort (see thread and related PR: Extend paypal node functions) - priorities, I get it, not judging.

If you were me, what would be best practice for my personal goals and community benefit - make it work and ideally share it:

  1. copy the core node wholesale into my custom node package, patch it, and release it in the meantime?
  2. Subclass the core node with my custom node?
  3. Stick with a simple node (see code below) and deploy as a custom node?

Suggestions are welcome :slight_smile:

Information on your n8n setup

  • n8n version: 1.77
  • Database (default: SQLite): default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): main
  • Running n8n via (Docker, npm, n8n cloud, desktop app): local
  • Operating system: Yes

Code

async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
		const items = this.getInputData();

		// Prepare the data that we'll return
		const returnData: INodeExecutionData[] = [];

		for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
			try {
				// Retrieve the spreadsheet ID from the current item
				const spreadsheetId = this.getNodeParameter('spreadsheetId', itemIndex) as string;

				const endpoint = `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}`;
				const qs: IDataObject = { includeGridData: false };

				const response = await this.helpers.requestOAuth2.call(this, 'googleSheetsOAuth2Api', {
					method: 'GET',
					uri: endpoint,
					qs,
					json: true,
				});

				const { sheets } = response;
				if (Array.isArray(sheets)) {
					sheets.forEach((sheet) => {
						const { sheetId, title } = sheet.properties || {};
						sheet;
						returnData.push({
							json: {
								spreadsheetId,
								sheetId,
								title,
							},
						});
					});
				}
			} catch (error) {
				throw new NodeOperationError(
					this.getNode(),
					`Google Sheets API Error: ${(error as Error).message}`,
					{
						itemIndex,
					},
				);
			}
		}

hello @forum.rfr

  1. Why avoid extending/copying the core node:
  • Core node updates would break your extended version
  • Maintaining a full copy creates confusion for users
  • Subclassing n8n nodes is not well-supported in the architecture
1 Like

HTTP with Predefined credential type, this is probably your answer, you usually don’t need a custom node

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.