n8n Sort Node: How to Sort Data in Your Workflows
The n8n Sort node lets you reorder items in your workflow based on the values of one or more fields. Whether you’re ranking results by score, organizing records alphabetically, or arranging dates in chronological order, the Sort node handles it cleanly without needing any custom code. It’s one of those utility nodes that looks simple on the surface but becomes indispensable once you know how to use it.
In this guide we cover everything you need to know about the Sort node — how it works, the different sort modes, multi-field sorting, and practical examples you can apply in your own workflows.
What Does the Sort Node Do?
The Sort node takes a list of items from the previous node and reorders them according to rules you define. You specify one or more fields to sort by, choose whether each field should sort ascending or descending, and the node outputs the same items in the new order.
The Sort node doesn’t filter or remove any items — every item that enters the node comes out the other side, just in a different sequence. This makes it great for preparing data before sending it to another system, displaying results in a meaningful order, or ensuring consistent output regardless of what order the source data arrived in.
Sort Modes: Simple vs. Advanced
The Sort node offers two modes. In Simple mode, you specify a field name and a sort direction (Ascending or Descending). This covers the vast majority of use cases — sorting a list of contacts by last name, ordering products by price, or ranking records by a numeric score. The field you sort by can be a string, number, boolean, or date — the node handles each type appropriately.
In Advanced mode, you can write a custom JavaScript comparison function to handle complex sorting logic that simple field-based sorting can’t express. For example, you might want to sort by a computed value, apply locale-specific string comparison, or implement a multi-tiered ranking based on business rules. The comparison function follows the same signature as JavaScript’s native Array.sort() comparator.
Sorting by Multiple Fields
One of the most useful features of the Sort node is multi-field sorting. You can add multiple sort criteria, and the node applies them in priority order — first sorting by the first field, then using subsequent fields as tiebreakers when the first field values are equal.
For example, to sort a list of employees first by department (A-Z) and then by salary (highest first) within each department, you’d add two sort fields: department Ascending, then salary Descending. Employees in the same department will be ordered by salary, while employees across departments will be ordered alphabetically by department name. This mirrors how ORDER BY clauses work in SQL.
Sorting Strings
When sorting string fields, the Sort node performs a lexicographic (alphabetical) comparison by default. This works well for most cases, but there are a few edge cases to be aware of. Numbers stored as strings will sort in string order rather than numeric order — so “10” comes before “9” alphabetically. If your field contains numeric strings that you want sorted numerically, convert them to actual numbers first using the Edit Fields node, then sort by the numeric version of the field.
Case sensitivity is another consideration. By default, string sorting is case-sensitive, meaning uppercase letters sort before lowercase letters in standard ASCII ordering. If you need case-insensitive sorting, use the Advanced mode and write a comparator that converts both strings to lowercase before comparing.
Sorting Dates
Dates sort correctly as long as they’re stored in a format that preserves chronological order when compared lexicographically — ISO 8601 format (YYYY-MM-DD or YYYY-MM-DDTHH:mm:ss) satisfies this requirement automatically. If your dates are in a different format (like MM/DD/YYYY), they may sort incorrectly because the month comes first in the string, which doesn’t match chronological order.
The fix is to normalize your dates to ISO format using the Edit Fields node or a Code node before the Sort node runs. Once in ISO format, sort Ascending for oldest-first or Descending for newest-first.
Practical Examples
Here are several real workflows where the Sort node earns its place. In a lead scoring pipeline, after enriching leads with scores from a scoring API, a Sort node orders them by score descending so the hottest leads appear first in the CRM import. In a product catalog sync, after fetching products from an e-commerce API, a Sort node organizes them by category name and then by price within each category before writing them to a database.
In a daily digest email, after aggregating news articles or notifications from multiple sources, a Sort node orders them by publish date so the email always shows content in chronological order. In a file processing queue, after listing files from a storage bucket, a Sort node orders them by file size ascending so smaller files are processed first, maximizing throughput. Each of these is a clean single-node solution that would otherwise require a Code node with custom sorting logic.
Tips and Common Mistakes
A few things to keep in mind when using the Sort node. First, the Sort node sorts the items it receives — make sure the data you want sorted is actually in the item array and not nested inside a sub-object. If your sortable value is buried at item.data.score, reference it using dot notation in the field name. Second, the Sort node preserves all fields — it doesn’t drop any data, just reorders. Third, if you’re sorting after a Merge node or an Aggregate node, double-check that the output structure is what you expect before adding the Sort. Finally, remember that Sort is non-destructive: if you need the original order preserved for a later branch, split the data before the Sort node rather than after.
