当前位置: 首页 > Skill >

N8n Create Nodes

N8n Create Nodes

N8n Create Nodes

Build production-ready n8n community nodes as npm packages, covering declarative and programmatic node styles. Use when user says "create an n8n node", "buil...

1.0.0 2026.11.27 594
获取Skill文件查看使用说明
作 者:许言 许可证: 更新时间:2026.11.27
本文目录展开

n8n Community Node Creation

Build production-ready n8n community nodes as npm packages. This skill covers both declarative (REST API wrapping) and programmatic (custom logic) node styles.

References: CREDENTIAL_PATTERNS.md | TRIGGER_PATTERNS.md | EXAMPLES.md | COMMON_MISTAKES.md

Quick Reference: Declarative vs Programmatic

Aspect Declarative Programmatic
Best for Simple REST API wrappers Custom logic, transforms, multi-call flows
HTTP handling Automatic via routing keys Manual in execute() method
Key property requestDefaults in description async execute() method
Imports needed INodeType, INodeTypeDescription + IExecuteFunctions, INodeExecutionData
Complexity Lower — declare routes, n8n handles requests Higher — full control over execution
Pagination Via operations.pagination config Manual loop in apiRequestAllItems helper
When to choose API maps 1:1 to operations, no transforms Need data manipulation, conditional logic, or chained calls

Decision rule: If every operation is a single HTTP request with simple input→body mapping and the response can be used as-is (or with minor postReceive transforms), use declarative. Otherwise, use programmatic.

Getting Started

IMPORTANT: Always start by cloning the official n8n-nodes-starter repository. Do NOT scaffold a project from scratch. The starter provides the correct TypeScript config, build tooling, linting, and project structure that n8n expects.

1. Clone the n8n-nodes-starter (Mandatory First Step)

# Clone the official starter — this is always the first step
git clone https://github.com/n8n-io/n8n-nodes-starter.git n8n-nodes-<yourservice>
cd n8n-nodes-<yourservice>

# Remove the starter's git history and reinitialize
rm -rf .git
git init

# Install dependencies
npm install

The starter repo provides:

  • Pre-configured tsconfig.json with the correct compiler options for n8n
  • Working package.json with build scripts (build, dev, lint, lintfix)
  • ESLint/Prettier configuration matching n8n conventions
  • Example node and credential files to use as a starting reference
  • Correct n8n object structure in package.json pointing to dist/ outputs

After cloning, rename/replace the example node and credential files with your own, and update package.json with your package name (n8n-nodes-<yourservice>), description, and the n8n.nodes / n8n.credentials arrays.

2. Required Files

File Purpose
nodes/<Name>/<Name>.node.ts Main node class (logic + description)
nodes/<Name>/<Name>.node.json Codex file (categories, doc links)
nodes/<Name>/<name>.svg Node icon (SVG, 60×60px recommended)
credentials/<Name>Api.credentials.ts Credential/auth definition
package.json npm config with n8n object linking nodes & credentials

Critical rules:

  • npm package name must start with n8n-nodes-
  • Class name must match filename (class MyService → MyService.node.ts)
  • Icon filename is lowercase (myservice.svg)

3. Package.json n8n Config

{
  "name": "n8n-nodes-myservice",
  "version": "0.1.0",
  "n8n": {
    "n8nNodesApiVersion": 1,
    "nodes": [
      "dist/nodes/MyService/MyService.node.js"
    ],
    "credentials": [
      "dist/credentials/MyServiceApi.credentials.js"
    ]
  }
}

Node Class Structure

Every node implements INodeType with a description object:

import { INodeType, INodeTypeDescription, NodeConnectionType } from 'n8n-workflow';

export class MyService implements INodeType {
  description: INodeTypeDescription = {
    displayName: 'My Service',
    name: 'myService',
    icon: 'file:myservice.svg',
    group: ['transform'],
    version: 1,
    subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
    description: 'Interact with My Service API',
    defaults: { name: 'My Service' },
    inputs: [NodeConnectionType.Main],
    outputs: [NodeConnectionType.Main],
    credentials: [
      { name: 'myServiceApi', required: true },
    ],
    properties: [
      // Resource and operation selectors, then parameter fields
    ],
  };
}

Required Description Properties

Property Type Notes
displayName string Shown in node panel
name string camelCase internal ID, unique across all nodes
icon string 'file:icon.svg' — ref to SVG in node folder
group string[] ['transform'], ['output'], ['input'], or ['trigger']
version number Start at 1, increment for breaking changes
subtitle string Expression template shown below node name
description string Short one-liner for node panel
defaults object { name: 'Display Name' }
inputs array [NodeConnectionType.Main] — empty [] for triggers
outputs array [NodeConnectionType.Main]
credentials array [{ name: 'credName', required: true }]
properties INodeProperties[] UI fields — resources, operations, parameters

Resource & Operation Pattern

The standard way to organize a node with multiple API resources:

properties: [
  // 1. Resource selector
  {
    displayName: 'Resource',
    name: 'resource',
    type: 'options',
    noDataExpression: true,       // REQUIRED on resource/operation selectors
    options: [
      { name: 'Contact', value: 'contact' },
      { name: 'Deal', value: 'deal' },
    ],
    default: 'contact',
  },
  // 2. Operation selector (per resource)
  {
    displayName: 'Operation',
    name: 'operation',
    type: 'options',
    noDataExpression: true,
    displayOptions: { show: { resource: ['contact'] } },
    options: [
      { name: 'Create', value: 'create', action: 'Create a contact' },
      { name: 'Delete', value: 'delete', action: 'Delete a contact' },
      { name: 'Get', value: 'get', action: 'Get a contact' },
      { name: 'Get Many', value: 'getAll', action: 'Get many contacts' },
      { name: 'Update', value: 'update', action: 'Update a contact' },
    ],
    default: 'create',
  },
  // 3. Operation-specific fields
  {
    displayName: 'Contact ID',
    name: 'contactId',
    type: 'string',
    required: true,
    default: '',
    displayOptions: {
      show: { resource: ['contact'], operation: ['get', 'update', 'delete'] },
    },
    description: 'The ID of the contact',
  },
  // 4. returnAll / limit pair for getAll
  {
    displayName: 'Return All',
    name: 'returnAll',
    type: 'boolean',
    default: false,
    displayOptions: { show: { resource: ['contact'], operation: ['getAll'] } },
    description: 'Whether to return all results or only up to a given limit',
  },
  {
    displayName: 'Limit',
    name: 'limit',
    type: 'number',
    default: 50,
    typeOptions: { minValue: 1 },
    displayOptions: {
      show: { resource: ['contact'], operation: ['getAll'], returnAll: [false] },
    },
    description: 'Max number of results to return',
  },
  // 5. Additional fields (optional params)
  {
    displayName: 'Additional Fields',
    name: 'additionalFields',
    type: 'collection',
    placeholder: 'Add Field',
    default: {},
    displayOptions: { show: { resource: ['contact'], operation: ['create', 'update'] } },
    options: [
      { displayName: 'Email', name: 'email', type: 'string', default: '' },
      { displayName: 'Phone', name: 'phone', type: 'string', default: '' },
    ],
  },
],

Key rules:

  • Always set noDataExpression: true on resource and operation selectors
  • Always include action on each operation option (used for the node action list)
  • Standard operation values: create, get, getAll, update, delete, upsert
  • Use displayOptions.show to conditionally display fields per resource/operation

Declarative Style

Add requestDefaults to description and routing to each operation. No execute() method.

description: INodeTypeDescription = {
  // ...standard properties...
  requestDefaults: {
    baseURL: 'https://api.myservice.com/v1',
    headers: { Accept: 'application/json' },
  },
  properties: [
    {
      displayName: 'Operation', name: 'operation', type: 'options',
      noDataExpression: true,
      options: [
        {
          name: 'Create', value: 'create', action: 'Create an item',
          routing: {
            request: { method: 'POST', url: '/items' },
          },
        },
        {
          name: 'Get', value: 'get', action: 'Get an item',
          routing: {
            request: { method: 'GET', url: '=/items/{{$parameter.itemId}}' },
          },
        },
      ],
      default: 'create',
    },
    // Map field values to request body/query
    {
      displayName: 'Name', name: 'name', type: 'string', default: '',
      routing: { send: { type: 'body', property: 'name' } },
    },
    {
      displayName: 'Tag', name: 'tag', type: 'string', default: '',
      routing: { send: { type: 'query', property: 'tag' } },
    },
  ],
};

Routing Keys

Key Purpose Example
routing.request HTTP method, URL, headers per operation { method: 'POST', url: '/items' }
routing.send Map parameter to body/query { type: 'body', property: 'name' }
routing.output.postReceive Transform response [{ type: 'rootProperty', properties: { property: 'data' } }]
routing.operations.pagination Auto-pagination config { type: 'offset', properties: { ... } }

postReceive Transforms

routing: {
  output: {
    postReceive: [
      { type: 'rootProperty', properties: { property: 'data' } },     // Extract nested data
      { type: 'filter', properties: { pass: '={{$responseItem.active}}' } },
      { type: 'limit', properties: { maxResults: '={{$parameter.limit}}' } },
      { type: 'set', properties: { value: '={{ { "id": $response.body.id } }}' } },
    ],
  },
},

Programmatic Style

Add an async execute() method for full control:

import {
  IExecuteFunctions, INodeExecutionData, INodeType,
  INodeTypeDescription, NodeConnectionType,
} from 'n8n-workflow';

export class MyService implements INodeType {
  description: INodeTypeDescription = { /* ...same as above, minus requestDefaults/routing... */ };

  async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
    const items = this.getInputData();
    const returnData: INodeExecutionData[] = [];
    const resource = this.getNodeParameter('resource', 0) as string;
    const operation = this.getNodeParameter('operation', 0) as string;

    for (let i = 0; i < items.length; i++) {
      try {
        let responseData;

        if (resource === 'contact') {
          if (operation === 'create') {
            const email = this.getNodeParameter('email', i) as string;
            const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
            const body: IDataObject = { email, ...additionalFields };
            responseData = await myServiceApiRequest.call(this, 'POST', '/contacts', body);
          }
          if (operation === 'getAll') {
            const returnAll = this.getNodeParameter('returnAll', i) as boolean;
            if (returnAll) {
              responseData = await myServiceApiRequestAllItems.call(
                this, 'contacts', 'GET', '/contacts',
              );
            } else {
              const limit = this.getNodeParameter('limit', i) as number;
              responseData = await myServiceApiRequest.call(
                this, 'GET', '/contacts', {}, { limit },
              );
              responseData = responseData.contacts;
            }
          }
        }

        const executionData = this.helpers.constructExecutionMetaData(
          this.helpers.returnJsonArray(responseData),
          { itemData: { item: i } },
        );
        returnData.push(...executionData);

      } catch (error) {
        if (this.continueOnFail()) {
          const executionErrorData = this.helpers.constructExecutionMetaData(
            this.helpers.returnJsonArray({ error: error.message }),
            { itemData: { item: i } },
          );
          returnData.push(...executionErrorData);
          continue;
        }
        throw error;
      }
    }

    return [returnData];
  }
}

Key Programmatic Helpers

Method Purpose
this.getInputData() Get input items array
this.getNodeParameter(name, index) Read a user-configured parameter
this.getCredentials('credName') Retrieve stored credentials
this.helpers.returnJsonArray(data) Wrap response as INodeExecutionData[]
this.helpers.constructExecutionMetaData(data, { itemData }) Link output to input items
this.continueOnFail() Check if user enabled "Continue On Fail"
this.helpers.request(options) Make HTTP request
this.helpers.requestWithAuthentication('credName', options) Authenticated HTTP request

UI Property Types

Type Description Common typeOptions
string Text input password: true, rows: N (multiline)
number Numeric input minValue, maxValue, numberPrecision
boolean Toggle —
options Single-select dropdown —
multiOptions Multi-select dropdown —
collection "Add Field" group of optional params —
fixedCollection Structured key-value groups multipleValues: true
json JSON code editor —
dateTime Date/time picker —
color Color picker —
resourceLocator Find by ID/URL/search mode: ['list', 'url', 'id']
resourceMapper Map fields to external schema —
notice Info box (not a parameter) —

Dynamic Options (Load from API)

{
  displayName: 'Channel',
  name: 'channelId',
  type: 'options',
  typeOptions: { loadOptionsMethod: 'getChannels' },
  default: '',
}

// In the node class:
methods = {
  loadOptions: {
    async getChannels(this: ILoadOptionsFunctions) {
      const credentials = await this.getCredentials('myServiceApi');
      const channels = await myServiceApiRequest.call(this, 'GET', '/channels');
      return channels.map((c: any) => ({ name: c.name, value: c.id }));
    },
  },
};

Codex File (.node.json)

{
  "node": "n8n-nodes-myservice.myService",
  "nodeVersion": "1.0",
  "codexVersion": "1.0",
  "categories": ["Miscellaneous"],
  "resources": {
    "credentialDocumentation": [{ "url": "" }],
    "primaryDocumentation": [{ "url": "" }]
  }
}

The node field format is <package-name>.<node-internal-name>.

Error Handling

Two Error Classes

Class Use For Import From
NodeApiError External API failures n8n-workflow
NodeOperationError Internal logic errors n8n-workflow
// In GenericFunctions.ts — wrap API errors:
throw new NodeApiError(this.getNode(), error as JsonObject);

// In execute() — wrap logic errors:
throw new NodeOperationError(this.getNode(), 'Unsupported operation', { itemIndex: i });

continueOnFail Pattern (ALWAYS use in execute loops)

See the programmatic style example above for the full pattern. The key structure:

  1. Wrap each item's processing in try/catch
  2. On catch: if this.continueOnFail(), push error data and continue
  3. Otherwise, re-throw the error

Naming Conventions

Element Convention Example
Node class PascalCase MyService
Trigger class PascalCase + Trigger MyServiceTrigger
Node file {Class}.node.ts MyService.node.ts
Credential class PascalCase + Api MyServiceApi
Credential file {Class}.credentials.ts MyServiceApi.credentials.ts
Internal name camelCase myService
npm package n8n-nodes-{name} n8n-nodes-myservice
Operation values camelCase verbs create, get, getAll, update, delete

Versioning Nodes

When making breaking changes, version the node instead of modifying in place:

import { INodeTypeBaseDescription, INodeTypeDescription, VersionedNodeType } from 'n8n-workflow';

export class MyService extends VersionedNodeType {
  constructor() {
    const baseDescription: INodeTypeBaseDescription = {
      displayName: 'My Service',
      name: 'myService',
      icon: 'file:myservice.svg',
      group: ['transform'],
      defaultVersion: 2,
      description: 'Interact with My Service',
    };
    const nodeVersions: IVersionedNodeType['nodeVersions'] = {
      1: new MyServiceV1(baseDescription),
      2: new MyServiceV2(baseDescription),
    };
    super(nodeVersions, baseDescription);
  }
}

Each version is a separate class with its own full INodeTypeDescription. Place in V1/ and V2/ subdirectories.

Testing & Publishing

Local Testing

# Build the node package
npm run build

# Link it into your n8n installation
npm link
cd ~/.n8n
npm link n8n-nodes-myservice

# Restart n8n — your node appears in the editor
n8n start

Publishing to npm

npm login
npm publish

After publishing, users install via: Settings → Community Nodes → Install → n8n-nodes-myservice

Ensure your package.json has:

  • "n8n" object with nodes and credentials arrays pointing to dist/ files
  • Correct main and files fields
  • "keywords": ["n8n-community-node-package"]

Best Practices

Do:

  • Use noDataExpression: true on resource/operation selectors
  • Include action on every operation option
  • Use constructExecutionMetaData with itemData for proper item linking
  • Implement continueOnFail() in every execute loop
  • Create GenericFunctions.ts for shared API request helpers
  • Use NodeConnectionType.Main instead of string 'main'
  • Use typeOptions: { password: true } for secret fields in credentials
  • Use returnAll/limit pair for list operations

Don't:

  • Modify v1 when adding features — create v2 instead
  • Forget the codex .node.json file
  • Use inputs other than [] for trigger nodes
  • Hard-code API base URLs in execute — use credentials or requestDefaults
  • Skip error wrapping — always use NodeApiError/NodeOperationError
  • Create large monolithic node files — split descriptions into separate files per resource

Troubleshooting

Quick reference for common issues. For the full catalog of 16+ errors with fixes, see references/COMMON_MISTAKES.md.

Node not appearing in editor

  1. Check package.json → n8n.nodes paths point to dist/ (not source)
  2. Rebuild: npm run build
  3. Re-link if using npm link and restart n8n

"Cannot find credential"

  • Verify the name in your credential class matches the name in the node's description.credentials array (case-sensitive)
  • Ensure credential file is listed in package.json → n8n.credentials

displayOptions not working

  • Resource/operation value strings must match exactly (case-sensitive) between the selector and displayOptions.show

Empty response data

  • For declarative nodes: verify postReceive → rootProperty extracts the correct JSON path from the API response

Item linking broken in output

  • Add constructExecutionMetaData with { itemData: { item: i } } wrapping every returnJsonArray call

Related Files

  • references/CREDENTIAL_PATTERNS.md — API key, OAuth2, and custom auth patterns
  • references/TRIGGER_PATTERNS.md — Webhook, poll, and event trigger implementations
  • references/EXAMPLES.md — Complete working node examples and helper patterns
  • references/COMMON_MISTAKES.md — Error catalog with fixes

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,042
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,036
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,023
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,023
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,021
OpenAI的Jalapeno芯片未落地,教你分辨300兆瓦算力消息

OpenAI计划在SB Energy租赁的数据中心部署约300兆瓦自研Jalapeno推理芯片,但目前双方仍处于洽谈阶段,交易细节与上线时间表均未公布。本文带你按报道原文核实项目所处阶段,厘清芯片发布、电力功率与实际推理算力的边界,并将融资意向与签约、开工、投运节点分开追踪,避免误将规划容量计入现有算力。

2026.12.02 1,017
Skill 文件
  • SKILL.md
    • n8n Community Node Creation
    • Quick Reference: Declarative vs Programmatic
    • Getting Started
      • 1. Clone the n8n-nodes-starter (Mandatory First Step)
      • 2. Required Files
      • 3. Package.json n8n Config
    • Node Class Structure
      • Required Description Properties
    • Resource & Operation Pattern
    • Declarative Style
      • Routing Keys
      • postReceive Transforms
    • Programmatic Style
      • Key Programmatic Helpers
    • UI Property Types
      • Dynamic Options (Load from API)
    • Codex File (.node.json)
    • Error Handling
      • Two Error Classes
      • continueOnFail Pattern (ALWAYS use in execute loops)
    • Naming Conventions
    • Versioning Nodes
    • Testing & Publishing
      • Local Testing
      • Publishing to npm
    • Best Practices
    • Troubleshooting
      • Node not appearing in editor
      • "Cannot find credential"
      • displayOptions not working
      • Empty response data
      • Item linking broken in output
    • Related Files
  • 项目或源文件

相关 Skill

更多
service-qa-coach service-qa-coach Review support quality for chat, email, phone, social DM, or marketplace service teams. Use when a team needs a QA scorecard, failure-mode analysis, coaching plan, calibration checklist, or service-improvement brief without live ticketing, CRM, or contact-center system access.
高中数学作业批改助手 高中数学作业批改助手 >图片识别 直接读取学生手写作答照片,识别公式、符号、步骤 🧮 自动推导 根据题目自动生成参考答案和评分细则,无需教师预设 📊 逐步给分 每个关键步骤独立评分,体现过程分 📝 结构化报告 输出含识别内容、参考答案、逐步评分、改进建议的完整报告 🗂 批量批改 支持一次性批改多道题,最终汇总得分表
Vibration Analysis Vibration Analysis 分析来自CMS趋势、RMS/峰值、频谱及SCADA报警的风机传动链(主轴、齿轮箱、发电机)振动数据。
Traditional Bone Tool Making Basics Traditional Bone Tool Making Basics Use when you need custom, durable, repairable tools like awls, needles, scrapers, harpoons, or fishing hooks made from local animal bones or antlers and comm...
音频混音工具 音频混音工具 名称:Sound Mixing Tool(标识 sound-mixing-tool) 短简介(≤60字):音乐/音效响度精确对齐 + 融合混音工作流:用 ffmpeg 两段式 loudnorm 把多组素材 LUFS 偏差压到 <0.10,再最小干预融合、导出可进引擎的独立分轨。 标签/关键词:音频混音 响度匹配 LUFS ffmpeg 游戏音频 音效设计 Wwise FMOD 分轨导出 后期处理 触发词:混音 · 响度匹配 · LUFS 对齐 · MIX 版本 · 音乐音效分轨 · 融合 · 不打架 · 不能盖住 适用场景 :游戏音频集成、影视短视频配乐、播客后期