n8n code formatter

n8n code nodes run inside an async function with access to $input, $node, workflow context, and more.

n8n code nodes let you write custom javascript or typescript to process workflow data. your code has access to $input, $node, $json, $workflow, and many other n8n-specific globals.

codefmt understands n8n's runtime environment. it won't flag $input.all() or items as undefined variables, and it handles the async function wrapper automatically.

n8n code nodes support two execution modes: run once for all items and run once for each item. codefmt recognizes the globals available in each mode, including $input.item for per-item execution. typescript is fully supported with type-aware formatting and linting.

frequently asked questions

what globals does n8n inject into code nodes?

n8n provides $input, $node, $workflow, $execution, $env, $now, $today, $json, $binary, $itemIndex, $runIndex, $prevNode, $parameter, $position, $jmespath, items, fetch, and console. codefmt recognizes all of these and won't flag them as undefined.

how do i return data from an n8n code node?

return an array of objects with a json property. for example: return [{ json: { name: 'value' } }]. codefmt formats this pattern correctly and preserves the expected return structure.

what is the difference between 'run once for all items' and 'run once for each item' in n8n?

n8n code nodes have two execution modes. 'run once for all items' gives you access to all input items via $input.all() and you return an array of items. 'run once for each item' runs your code once per item with $input.item or $json available for the current item. codefmt handles both modes and recognizes the globals specific to each.

does codefmt support typescript in n8n code nodes?

yes. codefmt supports typescript formatting and linting for n8n code nodes. n8n's code node supports typescript natively, and codefmt handles ts-specific syntax like type annotations, interfaces, and generics alongside n8n globals. select the n8n platform variant and your typescript code will be formatted correctly.

why does eslint flag $input and $json as undefined in n8n code?

standard linters don't know about n8n's injected globals like $input, $json, $node, and $workflow. they treat these as undefined variables. codefmt includes an n8n-specific lint plugin that registers all n8n globals, so you get accurate linting without false positives.