Description
n8n-nodes-rckflr-centroid
n8n community node that calculates the centroid of a list of numeric vectors. It is built for data pipelines that require averaging coordinates, embeddings or any multidimensional numeric representation.
Features
- Accepts vectors provided directly in the node or via incoming items.
- Validates dimensional consistency and numeric values before processing.
- Supports batch processing: each incoming item is evaluated independently.
- Optionally merges the calculated centroid with the original item payload.
Requirements
- n8n
>= 1.40.0 - Node.js
>= 20.0.0 - pnpm
>= 9.1.0
Installation
pnpm add n8n-nodes-rckflr-centroid
After installing, restart your n8n instance and add Centroid from the node palette.
Usage
- Choose the Vector Source:
- Auto (Parameter or Item): Uses the parameter if provided; otherwise reads from the incoming item (array at
item.jsonor fromitem.json.vectors). - Parameter: Read vectors from the Array of Vectors parameter (e.g.
[[1,2,3],[4,5,6]]). - Item JSON (Root Array): Read vectors from the root of
item.jsonwhen it contains an array of vectors. - Item JSON (Path): Read vectors from a dot-separated path under
item.json(e.g.data.vectors), configurable via Vector Path.
- Auto (Parameter or Item): Uses the parameter if provided; otherwise reads from the incoming item (array at
- Enable or disable Merge Output With Input depending on whether you want to keep the original item data.
- Execute the workflow. The node outputs a centroid array under the
centroidkey.
Example Workflow
An example workflow is available at examples/centroid-basic.json. Import it into n8n to see the node in action.
{
"nodes": [
{
"parameters": {
"values": {
"string": [
{
"name": "vectors",
"value": "[[0,0],[10,10],[5,5]]"
}
]
},
"options": {}
},
"name": "Set Vectors",
"type": "n8n-nodes-base.set",
"typeVersion": 2,
"position": [280, 300]
},
{
"parameters": {},
"name": "Centroid",
"type": "n8n-nodes-rckflr-centroid.centroid",
"typeVersion": 1,
"position": [540, 300]
}
]
}
Inputs & Outputs
| Aspect | Description |
|---|---|
| Input | Optional array of vectors. Provide via node parameter, item.json root array, or a dot-separated path under item.json (e.g. data.vectors). |
| Output | Each item contains a centroid array. When merging is enabled, the centroid is added to the original item JSON. |
| Errors | The node throws clear messages for malformed JSON, non-numeric components, empty vectors or mismatched dimensions. |
Error Handling
The node uses NodeOperationError for predictable failures. Errors include an item index (when available) to help you pinpoint problematic entries quickly.
Development
pnpm install
pnpm lint # ESLint rules for nodes and tests
pnpm test # Vitest unit tests with 80% coverage target
pnpm build # TypeScript build + icon copy to dist/
To run the node locally alongside n8n, follow the official local development guide.
Quality
- Linting powered by ESLint (
eslint-n8n-nodes-baseruleset). - Formatting enforced through Prettier.
- Unit tests executed with Vitest with coverage thresholds at 80% for lines, functions, branches and statements.
- Continuous integration configured in
.github/workflows/ci.yml.
Release Process
- Update
CHANGELOG.mdwith pending changes. - Bump the version in
package.jsonfollowing SemVer. - Tag the release (
git tag vX.Y.Z) and push tags. - Publish to npm with
pnpm publish --access public.
See REQUIREMENTS.md for the full list of project standards.
License
Released under the MIT License (c) Mauricio Perera.