Master advanced JavaScript scripting in your n8n workflow using the n8n code node. Learn data aggregation, external API calls, and binary file creation with this interactive n8n template.
Download this n8n workflow template and start using it instantly.
Developers and Technical Users looking to leverage custom JavaScript within n8n.
Users who need to perform complex data transformations or aggregations not possible with standard n8n nodes.
Automation specialists seeking to understand different execution modes of the n8n Code n8n node (Per Item vs. Once for All).
Anyone utilizing n8n templates to enhance their custom scripting skills.
The n8n Code n8n node is arguably the most powerful tool in the platform, allowing users to inject custom JavaScript logic directly into their n8n workflow. This specific n8n workflow acts as a hands-on guide, demonstrating four critical use cases for the Code n8n node:
By following this n8n template, users can quickly transition from basic flow building to scripting powerful, dynamic automations.
This comprehensive n8n workflow starts with a manual n8n trigger (Start Tutorial) and proceeds through several logical stages, each highlighting a different facet of the Code n8n node:
1. Sample Data n8n node initializes a list of user objects. The 2. Split Out Users n8n node ensures that each user becomes an individual item, preparing the data for 'Per Item' processing.3. Process Each User Code n8n node runs for each user item. It calculates the user's fullName and precise age using JavaScript date functions.4. Fetch External Data (Advanced) Code n8n node continues running per item. It demonstrates how to use this.helpers.httpRequest to call an external API (genderize.io) based on the user's first name, enriching the data with gender probability.5. Calculate Average Age Code n8n node switches to 'Run Once for All Items' mode. It uses the $items() function to access all results from the previous steps and calculates a single summary output containing the total user count and the average age. This is a crucial function of the n8n node when dealing with large datasets.6. Create a Binary File (Expert) Code n8n node aggregates the data again, generates a CSV string, and uses this.helpers.prepareBinaryData to convert the string into a ready-to-use binary report file within the n8n workflow.To install and test this n8n workflow, follow these steps:
Manual Trigger, click 'Run Workflow' and then click 'Start Tutorial' to execute the n8n workflow step-by-step. Start Tutorial (Manual Trigger): The starting n8n trigger point for manually running this n8n workflow.
1. Sample Data (Set n8n node): Initializes the workflow with a sample array of user objects, serving as the input for the tutorial.
2. Split Out Users (Split Out n8n node): Essential n8n node that converts the single item containing the user array into multiple individual items, allowing the subsequent Code n8n nodes to process them one by one.
3. Process Each User (Code n8n node): Function is to calculate derived data (fullName, age) for the current item. Key Configuration: Mode is set to Run Once for Each Item.
4. Fetch External Data (Advanced) (Code n8n node): Function is to demonstrate asynchronous operations using await this.helpers.httpRequest to fetch external data (gender guess) for the current user. Key Configuration: Mode is set to Run Once for Each Item.
5. Calculate Average Age (Code n8n node): Function is to aggregate data from all previous items. It uses $items() and JavaScript reduce to calculate the average age. Key Configuration: Mode is set to Run Once for All Items.
this.helpers.prepareBinaryData. Key Configuration: Mode is set to Run Once for All Items.Use this powerful n8n workflow to automatically search Hacker News for learning topics, extract top community-recommended resources using Google Gemini, and email the results.

Learn core API concepts like GET, POST, Query Parameters, Headers, and Timeouts using a structured n8n workflow. Perfect for beginners exploring n8n templates.

Use this robust n8n workflow to instantly sync Google Sheets leads to HubSpot, send simultaneous Slack and Gmail alerts, and implement automated follow-up reminders. Optimize your sales pipeline using n8n templates.

Learn to audit and synchronize inventory data between two systems using the powerful Compare Datasets n8n node. This essential n8n workflow identifies items to add, update, or remove.

Innovative builder with a passion for crafting automation solutions that solve real-world challenges. From streamlining workflows to driving efficiency, my work empowers teams and individuals to achieve more with less effort. Experienced in developing scalable tools and strategies that deliver results with n8n, supabase and cline.







































