コードノードを理解する

中級

これはEngineering分野の自動化ワークフローで、11個のノードを含みます。主にSet, Code, ManualTriggerなどのノードを使用。 コードノードでJavaScriptデータ処理を学ぶ:フィルタリング、分析、エクスポートの例

前提条件
  • 特別な前提条件なし、インポートしてすぐに使用可能

使用ノード (11)

ワークフロープレビュー
ノード接続関係を可視化、ズームとパンをサポート
ワークフローをエクスポート
以下のJSON設定をn8nにインポートして、このワークフローを使用できます
{
  "id": "1zR4oui3G7cMRnsP",
  "meta": {
    "instanceId": "2000c64071c20843606b95c63795bb0797c41036047055a6586498e855b96efc"
  },
  "name": "Understanding the code node",
  "tags": [],
  "nodes": [
    {
      "id": "735caeb3-82d9-4e58-aa90-d284a90a6100",
      "name": "付箋",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -600,
        -100
      ],
      "parameters": {
        "color": 7,
        "width": 460,
        "height": 700,
        "content": "## 🎯 WORKFLOW PURPOSE\nThis workflow demonstrates practical Code node usage for:\n\n• **Data filtering & transformation**\n• **Statistical calculations**  \n• **Formatting for external systems**\n• **Real-world business scenarios**\n\n💡 Perfect for learning JavaScript data manipulation in n8n!\n\nAuthor : **David Olusola**\n\n🚀 **n8n Coaching**\nUnlock the full potential of n8n with personalized, one-on-one coaching. Whether you're just getting started or need help solving a specific challenge, I’ll guide you step-by-step so you can build confidently and efficiently.\n👉 [Book Coaching Session](mailto:david@daexai.com?subject=n8n%20Coaching%20Request)\n\n **n8n Consulting**\nHave a complex automation project, unique integration needs, or want a custom workflow built from scratch? Let’s collaborate to design and implement a robust solution tailored to your business.\n📩 [Inquire About Consulting Services](mailto:david@daexai.com?subject=n8n%20Consultation%20Request)\n"
      },
      "typeVersion": 1
    },
    {
      "id": "69eeeaa0-490c-4cab-937c-edb266e6a0ed",
      "name": "付箋1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        620,
        -200
      ],
      "parameters": {
        "color": 7,
        "width": 680,
        "height": 340,
        "content": "## 🔧 CODE NODE BASICS\n\n**Key Points:**\n• Access input data via `items[0].json`\n• Always return array of objects\n• Use `.map()` to create multiple outputs\n• Return `[{ json: data }]` format\n\n**Common Patterns:**\n```javascript\n// Single output\nreturn [{ json: result }];\n\n// Multiple outputs\nreturn array.map(item => ({ json: item }));\n```"
      },
      "typeVersion": 1
    },
    {
      "id": "d7cafddc-1fb0-47c0-80a5-9584c781432d",
      "name": "付箋2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        680,
        120
      ],
      "parameters": {
        "color": 7,
        "width": 480,
        "height": 180,
        "content": "## 📊 EXAMPLE 1: FILTER & TRANSFORM\n\n**What it does:**\n• Filters users over 18 years old\n• Adds calculated bonus field (10% of salary)\n• Creates formatted email addresses\n• Outputs each user as separate item\n\n**Use cases:**\n• Lead qualification\n• Customer segmentation\n• Data enrichment"
      },
      "typeVersion": 1
    },
    {
      "id": "91e465df-24e5-49e9-8253-08d95c3d8860",
      "name": "付箋3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        680,
        320
      ],
      "parameters": {
        "color": 7,
        "width": 480,
        "content": "## 📈 EXAMPLE 2: CALCULATE STATS\n\n**What it does:**\n• Aggregates team data into statistics\n• Calculates averages, totals, distributions\n• Creates single summary object\n\n**Use cases:**\n• Dashboard data preparation\n• Report generation\n• KPI calculations\n• Business intelligence"
      },
      "typeVersion": 1
    },
    {
      "id": "15f8afd0-7694-490e-909a-1cccb1aad8b6",
      "name": "付箋4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        700,
        540
      ],
      "parameters": {
        "color": 7,
        "width": 280,
        "height": 340,
        "content": "## 🔄 EXAMPLE 3: FORMAT FOR EXPORT\n\n**What it does:**\n• Formats data for multiple output types\n• Creates CSV, email lists, API payloads\n• Adds metadata and timestamps\n\n**Use cases:**\n• API integrations\n• Email marketing prep\n• Data export functions\n• Multi-format reporting"
      },
      "typeVersion": 1
    },
    {
      "id": "c56969b0-8ce9-4f12-a5ab-81571dfe5c37",
      "name": "付箋5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -40,
        -80
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 280,
        "content": "## 🚀 QUICK START GUIDE\n\n**1. Click \"Test workflow\" to run**\n**2. Check each Code node's output**\n**3. Edit JavaScript code to experiment**\n**4. Copy patterns for your own workflows**\n\n**Pro Tips:**\n• Use `console.log()` for debugging\n• Test with small datasets first\n• Always handle edge cases\n• Return proper n8n format"
      },
      "typeVersion": 1
    },
    {
      "id": "11c7822e-f7ef-4417-a489-24528b50d189",
      "name": "ワークフロー実行時",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -140,
        360
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "8e750afa-737c-4cc9-bcd6-a886e247f545",
      "name": "サンプルデータ設定",
      "type": "n8n-nodes-base.set",
      "position": [
        100,
        340
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "99a2c0ab-5fdf-4d40-b989-492fc2393504",
              "name": "scenario",
              "type": "string",
              "value": "user_data"
            },
            {
              "id": "272adb73-f810-4f23-af05-f6f66fe6add8",
              "name": "usersJson",
              "type": "string",
              "value": "[{\"name\": \"Alice Johnson\", \"age\": 28, \"email\": \"alice@example.com\", \"role\": \"developer\", \"salary\": 75000}, {\"name\": \"Bob Smith\", \"age\": 17, \"email\": \"bob@example.com\", \"role\": \"intern\", \"salary\": 25000}, {\"name\": \"Charlie Brown\", \"age\": 35, \"email\": \"charlie@example.com\", \"role\": \"manager\", \"salary\": 95000}, {\"name\": \"Diana Ross\", \"age\": 22, \"email\": \"diana@example.com\", \"role\": \"designer\", \"salary\": 60000}]"
            }
          ]
        }
      },
      "typeVersion": 3.3
    },
    {
      "id": "29e2b762-60ea-4262-b64b-691cafceacaa",
      "name": "コード: フィルタ&変換",
      "type": "n8n-nodes-base.code",
      "position": [
        340,
        160
      ],
      "parameters": {
        "jsCode": "// EXAMPLE 1: Filter adults (age > 18) and add bonus field\nconst users = JSON.parse(items[0].json.usersJson);\n\n// Filter users over 18 and add calculated bonus\nconst adults = users\n  .filter(user => user.age > 18)\n  .map(user => ({\n    ...user,\n    bonus: user.salary * 0.1, // 10% bonus\n    fullEmail: `${user.name} <${user.email}>`,\n    isEligible: true\n  }));\n\n// Return each user as separate item for n8n\nreturn adults.map(user => ({ json: user }));"
      },
      "typeVersion": 2
    },
    {
      "id": "14efb99d-7522-4c7b-bb84-4f96e67cbdba",
      "name": "コード: 統計計算",
      "type": "n8n-nodes-base.code",
      "position": [
        420,
        440
      ],
      "parameters": {
        "jsCode": "// EXAMPLE 2: Aggregate data - calculate team statistics\nconst users = JSON.parse(items[0].json.usersJson);\n\n// Calculate team stats\nconst stats = {\n  totalEmployees: users.length,\n  averageAge: users.reduce((sum, user) => sum + user.age, 0) / users.length,\n  totalSalary: users.reduce((sum, user) => sum + user.salary, 0),\n  averageSalary: users.reduce((sum, user) => sum + user.salary, 0) / users.length,\n  roleDistribution: users.reduce((acc, user) => {\n    acc[user.role] = (acc[user.role] || 0) + 1;\n    return acc;\n  }, {}),\n  minAge: Math.min(...users.map(u => u.age)),\n  maxAge: Math.max(...users.map(u => u.age)),\n  eligibleForBonus: users.filter(u => u.age > 18).length\n};\n\n// Return single item with all statistics\nreturn [{ json: stats }];"
      },
      "typeVersion": 2
    },
    {
      "id": "f497b70c-805c-4efd-afb6-e1ec6c2adfa0",
      "name": "コード: エクスポート用フォーマット",
      "type": "n8n-nodes-base.code",
      "position": [
        380,
        720
      ],
      "parameters": {
        "jsCode": "// EXAMPLE 3: Format data for external API or email\nconst users = JSON.parse(items[0].json.usersJson);\n\n// Create formatted output for different use cases\nconst emailList = users.map(user => user.email).join(', ');\nconst csvFormat = users.map(user => \n  `${user.name},${user.age},${user.email},${user.role},${user.salary}`\n).join('\\n');\n\n// Create summary report\nconst report = {\n  reportDate: new Date().toISOString(),\n  teamOverview: {\n    totalMembers: users.length,\n    departments: [...new Set(users.map(u => u.role))],\n    payrollTotal: users.reduce((sum, u) => sum + u.salary, 0)\n  },\n  formattedData: {\n    emailList,\n    csvFormat,\n    jsonForApi: users.map(user => ({\n      id: user.name.toLowerCase().replace(' ', '_'),\n      displayName: user.name,\n      contact: user.email,\n      position: user.role,\n      compensation: user.salary,\n      eligibleForVoting: user.age >= 18\n    }))\n  }\n};\n\nreturn [{ json: report }];"
      },
      "typeVersion": 2
    }
  ],
  "active": false,
  "pinData": {
    "Set Sample Data": [
      {
        "json": {
          "scenario": "user_data",
          "usersJson": "[{\"name\": \"Alice Johnson\", \"age\": 28, \"email\": \"alice@example.com\", \"role\": \"developer\", \"salary\": 75000}, {\"name\": \"Bob Smith\", \"age\": 17, \"email\": \"bob@example.com\", \"role\": \"intern\", \"salary\": 25000}, {\"name\": \"Charlie Brown\", \"age\": 35, \"email\": \"charlie@example.com\", \"role\": \"manager\", \"salary\": 95000}, {\"name\": \"Diana Ross\", \"age\": 22, \"email\": \"diana@example.com\", \"role\": \"designer\", \"salary\": 60000}]"
        }
      }
    ]
  },
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "bb114702-f10c-42ed-90e4-dd9ff6421c8e",
  "connections": {
    "8e750afa-737c-4cc9-bcd6-a886e247f545": {
      "main": [
        [
          {
            "node": "29e2b762-60ea-4262-b64b-691cafceacaa",
            "type": "main",
            "index": 0
          },
          {
            "node": "14efb99d-7522-4c7b-bb84-4f96e67cbdba",
            "type": "main",
            "index": 0
          },
          {
            "node": "f497b70c-805c-4efd-afb6-e1ec6c2adfa0",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "11c7822e-f7ef-4417-a489-24528b50d189": {
      "main": [
        [
          {
            "node": "8e750afa-737c-4cc9-bcd6-a886e247f545",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
よくある質問

このワークフローの使い方は?

上記のJSON設定コードをコピーし、n8nインスタンスで新しいワークフローを作成して「JSONからインポート」を選択、設定を貼り付けて認証情報を必要に応じて変更してください。

このワークフローはどんな場面に適していますか?

中級 - エンジニアリング

有料ですか?

このワークフローは完全無料です。ただし、ワークフローで使用するサードパーティサービス(OpenAI APIなど)は別途料金が発生する場合があります。

ワークフロー情報
難易度
中級
ノード数11
カテゴリー1
ノードタイプ4
難易度説明

経験者向け、6-15ノードの中程度の複雑さのワークフロー

作成者
David Olusola

David Olusola

@dae221

I help ambitious businesses eliminate operational bottlenecks and scale faster with AI automation. My clients typically see 40-60% efficiency gains within 90 days. Currently accepting 3 new projects this quarter - david@daexai.com

外部リンク
n8n.ioで表示

このワークフローを共有

カテゴリー

カテゴリー: 34