금. 8μ›” 15th, 2025

D: Are you ready to unlock the full potential of n8n’s Code Node? 🀩 This powerful feature lets you inject custom JavaScript/Python logic into your workflows, opening doors to endless automation possibilities. Let’s dive into 10 practical examples that will transform how you automate tasks!


πŸ”₯ 1. Dynamic Data Transformation

Use Case: Convert raw API data into a clean format.

// Input: [{ "name": "John", "age": 30 }]
return items.map(item => ({
  userName: item.json.name.toUpperCase(),
  userAge: item.json.age + 5 // Add buffer for "data maturity"
}));

Output: [{ "userName": "JOHN", "userAge": 35 }]


πŸ“… 2. Date Magic

Use Case: Auto-calculate deadlines from today.

const dueDate = new Date();
dueDate.setDate(dueDate.getDate() + 7); // +7 days
return [{ json: { deadline: dueDate.toISOString().split('T')[0] } }];

Output: { "deadline": "2023-12-25" }


πŸ”„ 3. Conditional Routing

Use Case: Route tasks based on priority (e.g., “High” β†’ Slack, “Low” β†’ Email).

const priority = item.json.priority;
return [{ json: { ...item.json, routeTo: priority === "High" ? "slack" : "email" } }];

πŸ€– 4. AI-Powered Text Processing

Use Case: Use OpenAI to summarize text.

const { Configuration, OpenAIApi } = require('openai');
const config = new Configuration({ apiKey: $secrets.OPENAI_KEY });
const openai = new OpenAIApi(config);

const response = await openai.createCompletion({
  model: "text-davinci-003",
  prompt: `Summarize: "${item.json.text}"`,
});
return [{ json: { summary: response.data.choices[0].text } }];

πŸ“Š 5. Aggregating Data from Multiple APIs

Use Case: Merge weather + calendar data.

const weather = await $node["GetWeather"].json();
const events = await $node["GetCalendar"].json();
return [{
  json: {
    today: `🌧️ ${weather.temp}°C | πŸ“… ${events[0].title}`
  }
}];

πŸ” 6. Encryption/Decryption

Use Case: Secure sensitive data before DB storage.

const crypto = require('crypto');
const cipher = crypto.createCipheriv('aes-256-cbc', $secrets.CRYPTO_KEY, $secrets.IV);
let encrypted = cipher.update(item.json.password, 'utf8', 'hex');
encrypted += cipher.final('hex');
return [{ json: { encryptedPassword: encrypted } }];

πŸ›’ 7. E-Commerce Price Alerts

Use Case: Notify if product price drops below $X.

if (item.json.price  headlines.push($(el).text()));
return [{ json: { headlines } }];

🀯 10. Custom Error Handling

Use Case: Retry failed API calls with exponential backoff.

if (item.json.error) {
  const retries = item.json.retries || 0;
  if (retries < 3) {
    const delay = Math.pow(2, retries) * 1000;
    return [{ json: { ...item.json, retries: retries + 1 }, pairedItem: { ...item.pairedItem, wait: delay } }];
  }
}
return items; // Proceed if no error

πŸ’‘ Pro Tips

  • Debugging: Use console.log() β†’ View output in “Execution” tab.
  • Async/Await: Perfect for API calls (e.g., await $node["PreviousNode"].json()).
  • Libraries: Pre-installed (axios, lodash) or add via npm.

🎯 Why This Matters

The Code Node turns n8n from a “no-code” tool into a “low-code powerhouse” ⚑. Whether you’re cleaning data, calling APIs, or building complex logic, these examples showcase its flexibility.

Try one today! Which example excites you the most? Drop a comment below. πŸ‘‡

#n8n #Automation #WorkflowMagic #CodeNode

λ‹΅κΈ€ 남기기

이메일 μ£Όμ†ŒλŠ” κ³΅κ°œλ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. ν•„μˆ˜ ν•„λ“œλŠ” *둜 ν‘œμ‹œλ©λ‹ˆλ‹€