← 返回
未分类 中文

NPM for N8N Nodes

Build, structure, and publish npm packages for n8n custom community nodes. Use this skill whenever the user wants to create a custom n8n node, publish a node...
构建、打包并发布n8n 自定义社区节点的 npm 包,用于创建或发布自定义 n8n 节点。
encryptshawn encryptshawn 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 417
下载
💾 0
安装
1
版本
#latest

概述

n8n Custom Node — NPM Package Skill

Core Mental Model

Every n8n node follows one pattern:

getInputData()  →  loop items  →  do stuff  →  push to returnData  →  return [returnData]

Two file types do all the work:

  • Node file (nodes/MyNode/MyNode.node.ts) — UI fields + execute logic
  • Credential file (credentials/MyApi.credentials.ts) — auth definition

Everything else is project plumbing.


Project Structure

n8n-nodes-yourservice/
├── package.json              ← CRITICAL: must have n8n section + correct keyword
├── tsconfig.json
├── .eslintrc.js
├── gulpfile.js               ← copies SVG icons to dist/
├── index.js                  ← optional explicit entry point
├── nodes/
│   └── YourService/
│       ├── YourService.node.ts
│       ├── YourService.node.json   ← optional: codex metadata
│       └── yourservice.svg
├── credentials/
│   └── YourServiceApi.credentials.ts
└── dist/                     ← compiled output (never edit manually)

What to Read and When

This skill has focused reference files. Load only what you need:

Node Types (pick one)

If you need...Read
------
Standard request/response node (most common)references/examples/nodes/programmatic-node.md
Simple REST API, no complex logicreferences/examples/nodes/declarative-node.md
Trigger that polls an API on a schedulereferences/examples/nodes/trigger-node.md
Webhook that receives HTTP callsreferences/examples/nodes/webhook-node.md

Credentials (pick what matches your auth)

Auth typeRead
------
API key, Bearer token, custom header, query keyreferences/examples/credentials/api-key-patterns.md
OAuth2 (user login or machine-to-machine)references/examples/credentials/oauth2-patterns.md
Basic auth, multi-field, manual injectreferences/examples/credentials/other-patterns.md

Concepts (load when the topic comes up)

TopicRead
------
UI field types, displayOptions, collections, fixedCollectionreferences/concepts/node-properties.md
HTTP requests, bodies, headers, responses, binaryreferences/concepts/http-and-binary.md
Error types, continueOnFail, NodeApiError vs NodeOperationErrorreferences/concepts/error-handling.md
pairedItem, data flow, why item tracking mattersreferences/concepts/data-and-pairing.md
Node versioning, updating without breaking workflowsreferences/concepts/node-versioning.md

Project Setup & Publishing

TopicRead
------
package.json, tsconfig, gulpfile, eslintrc, index.jsreferences/templates/project-files.md
Local testing, npm link, n8n startreferences/templates/local-testing.md
npm publish, GitHub Actions, provenancereferences/templates/publishing.md
Common gotchas and silent failuresreferences/gotchas/common-gotchas.md

Quick-Start Pattern (copy this first)

// nodes/YourService/YourService.node.ts
import {
  IExecuteFunctions,
  INodeExecutionData,
  INodeType,
  INodeTypeDescription,
  NodeOperationError,
} from 'n8n-workflow';

export class YourService implements INodeType {
  description: INodeTypeDescription = {
    displayName: 'Your Service',
    name: 'yourService',
    icon: 'file:yourservice.svg',
    group: ['transform'],
    version: 1,
    description: 'Interact with Your Service API',
    defaults: { name: 'Your Service' },
    inputs: ['main'],
    outputs: ['main'],
    credentials: [{ name: 'yourServiceApi', required: true }],
    properties: [
      {
        displayName: 'Endpoint',
        name: 'endpoint',
        type: 'string',
        default: '/users',
        required: true,
      },
    ],
  };

  async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
    const items = this.getInputData();
    const returnData: INodeExecutionData[] = [];
    const credentials = await this.getCredentials('yourServiceApi');

    for (let i = 0; i < items.length; i++) {
      try {
        const endpoint = this.getNodeParameter('endpoint', i) as string;

        const response = await this.helpers.httpRequest({
          method: 'GET',
          url: `https://api.yourservice.com${endpoint}`,
          headers: {
            Authorization: `Bearer ${credentials.apiToken}`,
          },
        });

        returnData.push({ json: response, pairedItem: { item: i } });

      } catch (error) {
        if (this.continueOnFail()) {
          returnData.push({ json: { error: error.message }, pairedItem: { item: i } });
          continue;
        }
        throw new NodeOperationError(this.getNode(), error, { itemIndex: i });
      }
    }

    return [returnData];
  }
}

Essential APIs Cheat Sheet

// Input
const items = this.getInputData();

// Parameters
this.getNodeParameter('name', i) as string
this.getNodeParameter('count', i, 0) as number
this.getNodeParameter('options', i, {}) as IDataObject

// Credentials
const creds = await this.getCredentials('myCredentialName');

// HTTP
await this.helpers.httpRequest({ method, url, headers, qs, body })

// Error handling
this.continueOnFail()
throw new NodeOperationError(this.getNode(), message, { itemIndex: i })
throw new NodeApiError(this.getNode(), error)   // for API-level HTTP errors

// Output
returnData.push({ json: data, pairedItem: { item: i } })
return [returnData];

Pre-Publish Checklist

  • [ ] keywords in package.json includes "n8n-community-node-package"
  • [ ] n8n.nodes and n8n.credentials arrays point to dist/ .js paths
  • [ ] Node name is camelCase; displayName is human-readable
  • [ ] Credential name exactly matches string passed to getCredentials('...')
  • [ ] Every returnData.push() includes pairedItem: { item: i }
  • [ ] continueOnFail() is handled in all try/catch blocks
  • [ ] SVG icon exists in nodes/YourService/ and referenced as 'file:yourservice.svg'
  • [ ] npm run build succeeds (no TypeScript errors)
  • [ ] npm run lint passes (required for community submission)
  • [ ] Tested locally via npm link
  • [ ] Version bumped in package.json before publish

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-03 09:52 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

office-efficiency

Email MCP Helper

encryptshawn
访问和管理多个IMAP/SMTP邮箱账户,配备完整生命周期工具,支持读取、搜索、发送、回复、转发、文件夹和标签管理...
★ 0 📥 608
dev-programming

CodeConductor.ai

larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 72 📥 181,828
dev-programming

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 677 📥 327,271