> For the complete documentation index, see [llms.txt](https://doc.duaer.com/zh/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.duaer.com/zh/build/code.md).

# 在 Duaer 里用 Code 写一小段逻辑

在 Duaer 里，Code 用 JavaScript 或 Python 处理当前条目。只改几个字段时，优先用 Edit Fields。
## 写完再执行此步骤

1. 搜索 Code，接到上一个节点后面。
2. Mode 选 Run Once for All Items（整批跑一次）或 Run Once for Each Item（每条跑一次）。
3. Language 选 JavaScript 或 Python。
4. 在编辑器里写代码。JavaScript 里当前条目常用 $input.all() 或 $json。
5. 点执行此步骤，看输出。

表达式能搞定的改动，用 Edit Fields 更省事，见 [在 Duaer 里用 Edit Fields 改字段](/zh/build/edit-fields.md)。

Code 里引用上一节点时，有时要自己设 pairedItem，见 [在 Duaer 的 Code 节点里保留条目关联](/zh/data/data-mapping/data-item-linking/item-linking-code-node.md)。
## Questions

### Duaer 的 Code 默认是整批跑一次还是按条跑？

默认是 Run Once for All Items，整批只跑一次。要每条各跑一遍，改成 Run Once for Each Item。

