构建工作流

Output to the browser console

You can use console.log() or print() in the Code node to help when writing and debugging your code.

For help opening your browser console, refer to this guide by Balsamiq.

console.log (JavaScript)

For technical information on console.log(), refer to the MDN developer docs.

For example, copy the following code into a Code node, then open your console and run the node:

js
let a = "apple";
console.log(a);

print (Python)

For technical information on print(), refer to the Real Python's guide.

For example, set your Code node Language to Python, copy the following code into the node, then open your console and run the node:

python
a = "apple"
print(a)

Handling an output of [object Object]

If the console displays [object Object] when you print, check the data type, then convert it as needed.

To check the data type:

python
print(type(myData))

JsProxy

If type() outputs <class 'pyodide.ffi.JsProxy'>, you need to convert the JsProxy to a native Python object using to_py(). This occurs when working with data in the n8n node data structure, such as node inputs and outputs. For example, if you want to print the data from a previous node in the workflow:

python
previousNodeData = _("<node-name>").all();
for item in previousNodeData:
	# item is of type <class 'pyodide.ffi.JsProxy'>
	# You need to convert it to a Dict
	itemDict = item.json.to_py()
	print(itemDict)

Refer to the Pyodide documentation on JsProxy for more information on this class.

官方原文和授权

本页来自 N8N 英文官方网站固定快照,并转换成 xueai 静态页面。内容以 N8N 持续更新的官方页面为准。

来源、授权与修改

本站保留许可证、固定提交号、社区作者和修改说明,不代表 n8n 对本站背书。

查看许可证查看来源和修改说明