{"id":691,"date":"2026-05-18T21:06:21","date_gmt":"2026-05-18T13:06:21","guid":{"rendered":"https:\/\/junai.ai\/blog\/n8n-code-node-13\/"},"modified":"2026-05-18T21:36:45","modified_gmt":"2026-05-18T13:36:45","slug":"n8n-code-node-13","status":"publish","type":"post","link":"https:\/\/junai.ai\/blog\/n8n-code-node-13\/","title":{"rendered":"n8n Code \ub178\ub4dc \u2014 JavaScript \uc9c1\uc811 \uc791\uc131 (Ch.13)"},"content":{"rendered":"\n<!-- WordPress REST API \ubc1c\ud589\uc6a9 HTML (\uc790\ub3d9 \uc0dd\uc131) -->\n<!-- WP-FEATURED-MEDIA-ID: 708 -->\n<div style=\"max-width:800px;margin:0 auto;\">\n<style>:root{--p:#1e40af;--a:#3b82f6;--bg:#fafafa;--t:#1e293b;--tm:#64748b;--hs:#0f172a;--he:#5b21b6}*{box-sizing:border-box}body{margin:0;font-family:-apple-system,'Noto Sans KR',sans-serif;font-size:17px;line-height:1.75;color:var(--t);background:var(--bg);word-break:keep-all}.container{max-width:760px;margin:0 auto;padding:0 24px 80px}.hero{background:linear-gradient(135deg,var(--hs),var(--he));color:#fff;padding:80px 24px 60px;text-align:center}.hero .eyebrow{display:inline-block;font-size:14px;color:#a78bfa;font-weight:700;letter-spacing:.1em;text-transform:uppercase;margin-bottom:14px}.hero h1{font-size:36px;margin:0 0 16px;line-height:1.3;font-weight:800}.hero p{color:#c4b5fd;font-size:18px;max-width:640px;margin:0 auto;line-height:1.6}.hero img{width:100%;max-width:640px;height:auto;margin:32px auto 0;border-radius:10px;display:block}article{padding-top:48px}article h2{font-size:26px;margin:56px 0 20px;padding-left:14px;border-left:5px solid var(--a);line-height:1.4}article p{margin:16px 0}article strong{color:var(--p);font-weight:700}article code{background:#f1f5f9;padding:2px 8px;border-radius:4px;font-family:'SF Mono',Menlo,monospace;font-size:14px;color:#4338ca}.databox{background:#eff6ff;border-left:4px solid var(--a);padding:16px 20px;margin:24px 0;border-radius:0 8px 8px 0;font-size:15.5px}.warnbox{background:linear-gradient(135deg,#fef3c7,#fde68a);padding:16px 20px;margin:24px 0;border-radius:8px;font-size:15.5px}.cmd{background:#0f172a;color:#e2e8f0;padding:14px 18px;border-radius:8px;font-family:'SF Mono',Menlo,monospace;font-size:14px;overflow-x:auto;margin:14px 0;line-height:1.55;white-space:pre}.cmd .c{color:#fbbf24}.cmd .p{color:#64748b}.screenshot{margin:24px 0}.screenshot img{width:100%;height:auto;border:1px solid #e2e8f0;border-radius:8px;display:block}.screenshot figcaption{margin-top:10px;font-size:14.5px;color:var(--tm);text-align:center}.cta{background:#0f172a;color:#fff;padding:32px;border-radius:12px;margin:48px 0 0;text-align:center}.cta h3{color:#fff;margin:0 0 10px;font-size:20px}.cta a{display:inline-block;background:var(--a);color:#fff;padding:12px 26px;border-radius:8px;text-decoration:none;font-weight:700}@media(max-width:480px){.hero h1{font-size:26px}body{font-size:16px}article h2{font-size:22px}}<\/style>\n<header class=\"hero\">\n<span class=\"eyebrow\">n8n \ud55c\uad6d\uc5b4 \uad50\uc7ac \u00b7 Ch.13 \u00b7 \uc911\uae09\ud3b8 \uc2dc\uc791<\/span>\n<h1>Code \ub178\ub4dc \u2014 JavaScript \uc9c1\uc811<\/h1>\n<p>Set\u00b7IF\u00b7Switch \ub85c \uc548 \ud480\ub9ac\ub294 \ubcf5\uc7a1\ud55c \ubcc0\ud658\uc740 \uacb0\uad6d \ucf54\ub4dc. n8n \uc758 Code \ub178\ub4dc\ub294 JavaScript(\ub610\ub294 Python)\ub97c \ubc15\uc2a4 \uc548\uc5d0 \uadf8\ub300\ub85c \uc4f8 \uc218 \uc788\uac8c \ud569\ub2c8\ub2e4.<\/p>\n<img decoding=\"async\" src=\"https:\/\/junai.ai\/blog\/wp-content\/uploads\/2026\/05\/hero-5-13.jpg\" alt=\"JavaScript \ucf54\ub4dc \ubc15\uc2a4 \u2014 for of $input.all \ud328\ud134\">\n<\/header><div class=\"container\"><article>\n\n<p>\uc785\ubb38\u00b7\uae30\ucd08\ud3b8\uc758 \ub178\ub4dc\ub4e4 \u2014 Manual\u00b7Schedule\u00b7Webhook\u00b7HTTP\u00b7Set\u00b7IF\u00b7Switch\u00b7\uba54\uc77c\u00b7\uc2dc\ud2b8\u00b7Slack \u2014 \ub9cc\uc73c\ub85c\ub3c4 \uc6cc\ud06c\ud50c\ub85c 70% \ub294 \uc9e4 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \ub098\uba38\uc9c0 30% \ub294 &#8220;\uc774 \ub370\uc774\ud130\ub97c \uc880 \ubcf5\uc7a1\ud558\uac8c \uac00\uacf5\ud574\uc57c \ud558\ub294\ub370&#8230;&#8221; \uc758 \uc601\uc5ed. \uadf8\uac8c Code \ub178\ub4dc.<\/p>\n\n<h2>\uc5b8\uc81c Code \ub178\ub4dc\ub97c \uc368\uc57c \ud558\ub098<\/h2>\n\n<div class=\"databox\"><strong>Code \ub178\ub4dc\ub97c \uc4f0\ub294 \uc2e0\ud638 3\uac00\uc9c0<\/strong><br>\u2460 Set \ub178\ub4dc\uc758 \ud45c\ud604\uc2dd\uc774 \ud55c \uc904\uc744 \ub118\uae30 \uc2dc\uc791\ud568<br>\u2461 IF \ub178\ub4dc\uac00 5\uac1c \uc774\uc0c1 \uc911\ucca9\ub428<br>\u2462 \uac19\uc740 \ubcc0\ud658\uc744 \uc5ec\ub7ec \uc6cc\ud06c\ud50c\ub85c\uc5d0\uc11c \ubc18\ubcf5 \u2014 \ud568\uc218\ud654 \uc695\uad6c<\/div>\n\n<p>\ubc18\ub300\ub85c \u2014 <strong>\uc548 \uc368\ub3c4 \ub418\uba74 \uc548 \uc4f0\ub294 \uac8c \uc815\ub2f5<\/strong>. Code \ub178\ub4dc\ub294 \uac15\ub825\ud558\uc9c0\ub9cc \uc2dc\uac01\uc801 \uc6cc\ud06c\ud50c\ub85c\uc758 \uc7a5\uc810(\ub204\uac00 \ubd10\ub3c4 \ud750\ub984 \uc774\ud574) \uc744 \uae4e\uc544\uba39\uc5b4\uc694. &#8220;Set \ub178\ub4dc 5\uac1c\ub85c \ud480\ub9ac\uba74 Set 5\uac1c&#8221; \uac00 \ub354 \uc88b\uc2b5\ub2c8\ub2e4.<\/p>\n\n<h2>Code \ub178\ub4dc \u2014 \uc2e4\uc81c \ud654\uba74<\/h2>\n\n<figure class=\"screenshot\"><img decoding=\"async\" src=\"https:\/\/junai.ai\/blog\/wp-content\/uploads\/2026\/05\/01-node-settings-4.png\" alt=\"Code \ub178\ub4dc \uac80\uc0c9 \uacb0\uacfc \u2014 Code \ud56d\ubaa9\uc774 \uccab \uacb0\uacfc\ub85c\"><figcaption>\uc774\uc804 \ub178\ub4dc + \u2192 &#8220;code&#8221; \uac80\uc0c9 \u2192 Code \ub178\ub4dc. \uc5b8\uc5b4 \uc120\ud0dd(JavaScript \/ Python) \ud6c4 \ud070 \uc5d0\ub514\ud130\uac00 \uc5f4\ub9bd\ub2c8\ub2e4.<\/figcaption><\/figure>\n\n<p>Code \ub178\ub4dc\uc758 \ub450 \ubaa8\ub4dc:<\/p>\n\n<div class=\"cmd\"><span class=\"c\">Mode<\/span>:\n  Run Once for All Items   (items \uc804\uccb4 \ud55c \ubc88 \u2014 \uc9d1\uacc4\u00b7\uc815\ub82c \ub4f1)\n  Run Once for Each Item   (item \ub9c8\ub2e4 \ud55c \ubc88 \u2014 \ubcc0\ud658\u00b7\ub9e4\ud551 \ub4f1)<\/div>\n\n<h2>\ud328\ud134 1 \u2014 \uc804\uccb4 item \ubcc0\ud658 (Run Once for All)<\/h2>\n\n<div class=\"cmd\">\/\/ items 100\uac1c \ubc1b\uc544 \uac01\uc790 \ubcc0\ud658\nconst out = [];\nfor (const item of $input.all()) {\n  const u = item.json;\n  out.push({\n    json: {\n      <span class=\"c\">name<\/span>: u.firstName + &#8216; &#8216; + u.lastName,\n      <span class=\"c\">total<\/span>: u.qty * u.price,\n      <span class=\"c\">isVIP<\/span>: u.amount > 100000,\n    }\n  });\n}\nreturn out;<\/div>\n\n<p><code>$input.all()<\/code> \uc774 \uc774\uc804 \ub178\ub4dc\uc758 items \ubc30\uc5f4. \uac01\uc790 \ubcc0\ud658\ud574 \uc0c8 \ubc30\uc5f4 \ubc18\ud658. <strong>\ubc18\ud658 \ud615\uc2dd\uc740 \ubb34\uc870\uac74 <code>[{json: {...}}, ...]<\/code><\/strong> \u2014 \uc774\uac8c n8n \uc758 \ud45c\uc900 item \ud615\ud0dc(Ch.4).<\/p>\n\n<h2>\ud328\ud134 2 \u2014 item \ubcc4 \ucc98\ub9ac (Run Once for Each)<\/h2>\n\n<div class=\"cmd\">\/\/ \uc774 \ubaa8\ub4dc\uc5d0\uc120 $json \uc774 \uc790\ub3d9 \ud604\uc7ac item\nreturn {\n  json: {\n    <span class=\"c\">summary<\/span>: `${$json.name}\ub2d8: ${$json.total.toLocaleString()}\uc6d0`,\n    <span class=\"c\">tag<\/span>: $json.total > 50000 ? &#8216;\ud070\uc8fc\ubb38&#8217; : &#8216;\uc18c\uc8fc\ubb38&#8217;,\n  }\n};<\/div>\n\n<p>\uc774 \ubaa8\ub4dc\ub294 n8n \uc774 \uc54c\uc544\uc11c item \ub9c8\ub2e4 \ucf54\ub4dc\ub97c \uc2e4\ud589. \ucf54\ub4dc\ub294 \ud55c item \ub9cc \ucc98\ub9ac\ud558\uba74 \ub418\uace0, \ubc18\ud658\ub3c4 \ud55c \uac1d\uccb4. <strong>Set \ub178\ub4dc\uc640 \uac70\uc758 \uac19\uc740 \uc77c<\/strong>\uc778\ub370 \ub354 \uc790\uc720\ub85c\uc6c0.<\/p>\n\n<h2>\ud328\ud134 3 \u2014 \uc678\ubd80 \ub370\uc774\ud130 \ud65c\uc6a9 + \uc9d1\uacc4<\/h2>\n\n<div class=\"cmd\">\/\/ \ub9e4\ucd9c 100\uac74\uc758 \uce74\ud14c\uace0\ub9ac\ubcc4 \ud569\uacc4\nconst by = {};\nfor (const it of $input.all()) {\n  const c = it.json.category;\n  by[c] = (by[c] || 0) + it.json.amount;\n}\nreturn Object.entries(by).map(([cat, sum]) => ({\n  json: { category: cat, total: sum }\n}));<\/div>\n\n<p>\uc785\ub825 100\uac74 \u2192 \ucd9c\ub825 \uce74\ud14c\uace0\ub9ac \uc218\ub9cc\ud07c. n8n \uc758 \uc77c\ubc18 \ub178\ub4dc\ub860 SQL GROUP BY \uac00 \uc5b4\ub835\uc9c0\ub9cc Code \ub178\ub4dc\ub860 5\uc904.<\/p>\n\n<p><strong>n8n \ud2b9\uc218 \ud568\uc218 + \uc678\ubd80 \ub77c\uc774\ube0c\ub7ec\ub9ac<\/strong><\/p>\n\n<div class=\"cmd\"><span class=\"p\"># n8n \ud2b9\uc218 \ud568\uc218 (Code \ub178\ub4dc\uc5d0\uc11c\ub9cc)<\/span>\n$input.all()       <span class=\"p\">\/\/ \uc785\ub825 items \uc804\uccb4<\/span>\n$input.first()     <span class=\"p\">\/\/ \uccab item<\/span>\n$input.itemMatching(0)  <span class=\"p\">\/\/ \uc778\ub371\uc2a4 \ub9e4\uce6d<\/span>\n$workflow.id       <span class=\"p\">\/\/ \uc6cc\ud06c\ud50c\ub85c ID<\/span>\n$execution.id      <span class=\"p\">\/\/ \uc774\ubc88 \uc2e4\ud589 ID<\/span>\n\n<span class=\"p\"># \ub0b4\uc7a5 \ub77c\uc774\ube0c\ub7ec\ub9ac<\/span>\nDateTime           <span class=\"p\">\/\/ Luxon (Ch.5 \uc640 \ub3d9\uc77c)<\/span>\ncrypto             <span class=\"p\">\/\/ Node.js crypto<\/span>\nBuffer             <span class=\"p\">\/\/ \ubc14\uc774\ub108\ub9ac \ucc98\ub9ac<\/span><\/div>\n\n<p>\uc678\ubd80 npm \ud328\ud0a4\uc9c0\ub294 \uc124\uce58 \uc548 \ub428 (\ubcf4\uc548). \ud544\uc694\ud558\uba74 HTTP Request \ub178\ub4dc\ub85c \uc678\ubd80 API \ud638\ucd9c\ud574 \uacb0\uacfc \ubc1b\uc544\uc624\ub294 \ud328\ud134 \uad8c\uc7a5.<\/p>\n\n<div class=\"warnbox\"><strong>Python \ubaa8\ub4dc<\/strong> \u2014 n8n \uc758 Python Code \ub178\ub4dc\ub294 Pyodide \uae30\ubc18(\ube0c\ub77c\uc6b0\uc800 \uc548 Python). \uc2e4\ud589 \uc18d\ub3c4 JS \ub300\ube44 \ub9e4\uc6b0 \ub290\ub9bc, \uc678\ubd80 \ub77c\uc774\ube0c\ub7ec\ub9ac \uac70\uc758 \uc5c6\uc74c. JavaScript \uc775\uc219\uce58 \uc54a\uc544\ub3c4 \ud55c \ubc88 JS \ub85c \uac00\ub294 \uac8c \ud6a8\uc728\uc801.<\/div>\n\n<p>\ub2e4\uc74c Ch.14 \u2014 Loop \u00b7 Split In Batches. 1\ub9cc \uac74 \ub370\uc774\ud130\ub97c 100\uac1c\uc529 \ub04a\uc5b4 \ucc98\ub9ac\ud558\ub294 \ud328\ud134. Code \ub178\ub4dc\uc758 \ub2e8\uc810(\uba54\ubaa8\ub9ac)\uc744 \ubcf4\uc644\ud558\ub294 \uc815\uacf5\ubc95.<\/p>\n\n<div class=\"cta\"><h3>n8n \ud55c\uad6d\uc5b4 \uad50\uc7ac \u00b7 Ch.13 \uc644\ub8cc \u2014 \uc911\uae09\ud3b8 \uc2dc\uc791<\/h3><p>\ub2e4\uc74c \ud3b8 \u2192 Ch.14 Loop \u00b7 Split In Batches<\/p><a href=\"https:\/\/junai.ai\/blog\/category\/n8n\/\">\uc804\uccb4 \uc2dc\ub9ac\uc988 \ubcf4\uae30<\/a><\/div>\n\n<\/article><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>n8n Code \ub178\ub4dc\ub85c \ubcf5\uc7a1\ud55c \ub85c\uc9c1 JavaScript\/Python \uc9c1\uc811 \uc791\uc131. \\$input\u00b7\\$json\u00b7return \ud328\ud134 + \uc790\uc8fc \uc4f0\ub294 \ubcc0\ud658 \uc608\uc81c. \uc911\uae09 Ch.13.<\/p>\n","protected":false},"author":1,"featured_media":708,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-691","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-n8n"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/posts\/691","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/comments?post=691"}],"version-history":[{"count":1,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/posts\/691\/revisions"}],"predecessor-version":[{"id":715,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/posts\/691\/revisions\/715"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/media\/708"}],"wp:attachment":[{"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/media?parent=691"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/categories?post=691"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/tags?post=691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}