Spanish Total.js
English
Documentation For AI agents
Contents

Code

Write a few lines of JavaScript that run on each message.

.md GitHub
On this page

The Code node runs your JavaScript on every message it receives, on the server. Download it from the Common group of the catalog.

SettingWhat it does
NameA name for your own reference.
Number of outputsHow many outputs the node has: Output #1, Output #2 and so on.
CodeYour JavaScript.

What you can use

NameWhat it is
valueThe data of the message.
send(data)Sends data to the first output.
$.send('output2', data)Sends data to the second output. Use output3, output4 and so on for the next ones.
instance.replace('{KEY}')Returns the text with each {KEY} replaced by the variable of that name.
console.log(...)Writes a line to the Console or to the terminal.
throw new Error('...')Stops the message and reports an error.

A message that you do not send on does not go further.

Examples

Answer with a greeting:

send({ message: 'Hello, ' + (value.query.name || 'world') + '!' });

Send to one of two outputs:

if (!value.product) {
    $.send('output2', { error: 'The product is required.' });
    return;
}
send({ response: { success: true, product: value.product } });

More examples are in the recipes.

Made in Europe