---
title: Code
project: LessCode
version: 1.0
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/lesscode/1-0/reference/code/
updated: 2026-11-19T04:41:16.354Z
---

# Code

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

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

| Setting | What it does |
|---|---|
| **Name** | A name for your own reference. |
| **Number of outputs** | How many outputs the node has: **Output #1**, **Output #2** and so on. |
| **Code** | Your JavaScript. |

## What you can use

| Name | What it is |
|---|---|
| `value` | The 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](../../guides/variables/) of that name. |
| `console.log(...)` | Writes a line to the [Console](../../guides/console/) or to the terminal. |
| `throw new Error('...')` | Stops the message and reports an [error](../../guides/errors/). |

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

## Examples

Answer with a greeting:

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

Send to one of two outputs:

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

More examples are in the [recipes](../../recipes/get-endpoint/).
