Skip to content
GitHub

n8n-code-javascript - n8n JavaScript Code

n8n-code-javascript

n8n JavaScript Code

Community Automation
GitHub

Description

Write JavaScript code in n8n Code nodes for complex data transformation and logic

Use Cases

  • Complex data transformation
  • Custom business logic
  • Data validation and cleaning
  • Dynamic content generation
  • External library calls

Core Capabilities

  • Data Processing: Access and transform input data
  • Logic Control: Conditionals and loops
  • Output Format: Generate correct output structure
  • Error Handling: Catch and handle exceptions

Example

// n8n Code node example
// Transform order data to invoice format
const orders = $input.all();
const invoices = orders.map(order => {
const items = order.json.items;
const total = items.reduce((sum, item) =>
sum + item.price * item.quantity, 0);
return {
json: {
invoiceId: `INV-${order.json.orderId}`,
customer: order.json.customer,
items: items,
subtotal: total,
tax: total * 0.1,
total: total * 1.1,
date: new Date().toISOString()
}
};
});
return invoices;

Notes

  • Use $input.all() to get all inputs
  • Return correct data structure
  • Handle empty data cases
  • Add appropriate logging

Applicable Roles

Developer

Tags

n8njavascriptcodetransformation