Creating Custom Nodes
Relevant source files
The following files were used as context for generating this wiki page:
- packages/workflow/src/interfaces.ts
- packages/nodes-base/nodes/Example/Example.node.ts
- packages/frontend/editor-ui/src/constants.ts
- packages/nodes-base/nodes/HttpRequest/HttpRequest.node.json
- packages/nodes-base/nodes/Webhook/Webhook.node.json
- packages/nodes-base/nodes/Function/Function.node.json
- packages/nodes-base/nodes/If/If.node.json
- packages/nodes-base/nodes/Merge/Merge.node.json
Custom nodes are the fundamental building blocks of n8n workflows. They encapsulate the logic for interacting with APIs, transforming data, or controlling the flow of execution. Creating a custom node allows developers to extend n8n's capabilities to integrate with any service or perform specialized tasks not covered by the built-in nodes.
A node is primarily composed of two parts: a TypeScript file (.node.ts) that defines the node's behavior and user interface, and a JSON file (.node.json) that provides metadata for display in the n8n editor, such as categories and documentation links. This structure separates the core logic from its presentation and discoverability within the platform.
Node Architecture
The following diagram illustrates the relationship between the main components of a custom node and how they are interpreted by the n8n system.
This diagram shows that the .node.ts file provides the execution logic to the workflow executor and the UI parameter definitions to the editor, while the .node.json file supplies supplementary metadata to the editor.
Sources: packages/nodes-base/nodes/Example/Example.node.ts, packages/nodes-base/nodes/HttpRequest/HttpRequest.node.json
Node Metadata (.node.json)
The .node.json file contains metadata about the node that is used by the n8n frontend to categorize, display, and provide resources for the node.
| Property | Description | Example |
|---|---|---|
node | The unique identifier for the node. | "n8n-nodes-base.httpRequest" |
nodeVersion | The version of the node logic. | "1.0" |
codexVersion | The version of the metadata schema. | "1.0" |
categories | An array of high-level categories the node belongs to. | ["Development", "Core Nodes"] |
resources | An object containing links to primary documentation, credential documentation, and other generic resources like blog posts. | See HttpRequest.node.json |
alias | An array of search terms to help users find the node. | ["API", "Request", "URL", "Build", "cURL"] |
subcategories | An object mapping a main category to a list of subcategories for finer-grained organization in the node creation panel. | {"Core Nodes": ["Helpers"]} |
Sources: packages/nodes-base/nodes/HttpRequest/HttpRequest.node.json:2-6, 8, 102-104, packages/nodes-base/nodes/Webhook/Webhook.node.json:5, 52-54
Node Categories and Subcategories
Nodes are organized in the UI based on categories and subcategories. These are defined as constants and used in the .node.json files to ensure consistency.
| Category/Subcategory | Constant Name |
|---|---|
| Core Nodes | CORE_NODES_CATEGORY |
| Data Transformation | TRANSFORM_DATA_SUBCATEGORY |
| Files | FILES_SUBCATEGORY |
| Flow | FLOWS_CONTROL_SUBCATEGORY |
| Helpers | HELPERS_SUBCATEGORY |
| AI | AI_SUBCATEGORY |
| Human in the Loop | HUMAN_IN_THE_LOOP_CATEGORY |
| Custom Nodes | CUSTOM_NODES_CATEGORY |
Example Usage in Merge.node.json:
{
"node": "n8n-nodes-base.merge",
"categories": ["Core Nodes"],
"subcategories": {
"Core Nodes": ["Flow", "Data Transformation"]
}
}
Sources: packages/frontend/editor-ui/src/constants.ts:348-360, packages/nodes-base/nodes/Merge/Merge.node.json:4, 30-32, packages/nodes-base/nodes/If/If.node.json:29-31
Node Implementation (.node.ts)
The .node.ts file is a class that implements the INodeType interface. This class is responsible for defining the node's properties, which appear in the UI, and the execute method, which contains the node's runtime logic.
Sources: packages/workflow/src/interfaces.ts:2792-2800, packages/nodes-base/nodes/Example/Example.node.ts:18
Core Structure
The basic structure of a node implementation class is as follows:
This diagram shows a node class (ExampleNode) implementing the INodeType interface, which requires a description object and an execute method.
Sources: packages/nodes-base/nodes/Example/Example.node.ts:18, packages/workflow/src/interfaces.ts:2792-2800
Node Description (INodeTypeDescription)
The description property of the node class holds an object of type INodeTypeDescription. This object defines all the visible aspects of the node in the n8n editor.
| Property | Description |
|---|---|
displayName | The name of the node displayed in the UI. |
name | The internal name of the node, used for identification. |
icon | The icon to display for the node (e.g., icon: 'file:example.svg'). |
group | The group the node belongs to, used for categorization. |
version | The version of the node. |
subtitle | A dynamic subtitle that can be displayed on the node in the canvas. |
description | A longer description of the node's purpose. |
defaults | Default values for the node's position, width, and color. |
inputs | Defines the number of allowed input connections (e.g., ['main']). |
outputs | Defines the output connections (e.g., ['main']). |
properties | An array of INodeProperties objects that define the UI fields in the node's parameter panel. |
Sources: packages/nodes-base/nodes/Example/Example.node.ts:20-36, packages/workflow/src/interfaces.ts:2714-2776
Defining UI Parameters (properties)
The properties array is the most critical part of the description. Each object in this array defines a single UI control (like a text input, dropdown, or toggle) in the node's settings panel.
Here is an example of a simple string property from the Example.node.ts file:
// packages/nodes-base/nodes/Example/Example.node.ts:39-46
{
displayName: 'My String',
name: 'myString',
type: 'string',
default: '',
placeholder: 'Placeholder text',
description: 'This is a description for the string parameter',
},
The INodeProperties interface has many attributes to customize the field's behavior.
| Attribute | Description |
|---|---|
displayName | The label for the UI field. |
name | The key used to store the value of this field. |
type | The data type of the field, which determines the UI control (e.g., string, number, boolean, options, collection). |
default | The default value for the field. |
description | A tooltip or help text for the field. |
placeholder | Placeholder text for input fields. |
required | If true, the field must have a value. |
displayOptions | Used to conditionally show or hide this property based on the values of other properties. |
options | For options type fields, this is an array of available choices. |
Sources: packages/workflow/src/interfaces.ts:1680-1845, packages/nodes-base/nodes/Example/Example.node.ts:38-118
Execution Logic (execute method)
The execute method is the heart of the node. It is called when the workflow runs, and it's responsible for processing the input data and producing output data.
The basic flow of the execute method is:
- Iterate through the incoming items.
- For each item, retrieve the values of the node's parameters using
this.getNodeParameter(). - Perform the desired logic (e.g., call an API, transform data).
- Prepare the return data in the
INodeExecutionDataformat. - Return an array of output data, which will be passed to the next node(s).
The following flowchart illustrates this process:
This diagram shows the typical loop within a node's execute method to process each incoming item individually.
Sources: packages/nodes-base/nodes/Example/Example.node.ts:121-157
Summary
Creating a custom n8n node involves a clear separation of concerns. The .node.json file handles metadata for discoverability and presentation in the editor, leveraging a system of categories and subcategories. The .node.ts file contains the core implementation, where the description object defines the node's UI parameters and the execute method implements the business logic. By following the INodeType and INodeProperties interfaces, developers can build powerful, reusable, and well-integrated nodes for any workflow automation task.