---
title: Message reference
project: Flow
version: 11.1
section: development
language: en
license: MIT
url: https://totaljs.es/docs/flow/11-1/development/message-api/
updated: 2026-11-20T06:50:57.962Z
---

# Message reference

> The properties and methods of a message in the server code.

A message carries data from an output of one node to an input of another. `instance.message` receives it, usually as `$`:

```js
instance.message = function($) {
	var data = $.data;
	$.send('output', data);
};
```

Every message must be sent on or ended. See [Inputs, outputs and messages](../inputs-outputs/).

## API

### $.data

Type: `property`

The data of the message.

### $.input

Type: `property`

The id of the input on which the message arrived.

### $.output

Type: `property`

The id of the output from which the message came.

### $.fromid

Type: `property`

The id of the node that sent the message.

### $.fromcomponent

Type: `property`

The id of the component of the node that sent the message.

### $.toid

Type: `property`

The id of the node that received the message.

### $.repo

Type: `property`

An object that travels with the message from node to node.

A node stores values in it, and the nodes after it read them.

Example: Keep a value
```js
$.repo.orderid = 1001;
$.send('output');
```

### $.refs

Type: `property`

References shared by all copies of the message.

The **Route** component stores the HTTP request in `$.refs.controller`, and the **Response** component answers through it.

### $.instance

Type: `property`

The node that received the message.

### $.main

Type: `property`

The FlowStream.

### $.error

Type: `property`

The error stored by `$.throw()`.

### $.send(output, [data])

Type: `method`

Sends the message to the nodes connected to an output.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `output` | `String` | yes |  | The id of the output. |
| `data` | `Object` | no |  | New data for the message. |

Returns: `Number` The number of nodes that received the message.

Without `data`, the message keeps its data. With `null` as `output`, it goes to every output that has a connection. When no node receives it, the message ends.

Example: Send new data
```js
$.send('output', { name: 'Jane' });
```

### $.destroy()

Type: `method`

Ends the message.

Call it for every message that you do not send on. `$.end()` does the same.

### $.throw(error)

Type: `method`

Reports an error to the designer and stores it in `$.error`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `error` | `String` | yes |  | The error message. |

It does not end the message.

Example: Report and end
```js
$.throw('Demo error');
$.destroy();
```

### $.replace(text, [data])

Type: `method`

Fills in variables, and other keys from the message.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `text` | `String` | yes |  | The text with keys in braces. |
| `data` | `Object` | no |  | Values to use instead of the message. |

Returns: `String` The text with the values.

Works like `instance.replace()`, but keys that are not variables are read from the message, for example `{data.name}`. `$.variables()` does the same.

### $.rewrite(data)

Type: `method`

Replaces the data of the message.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `data` | `Object` | yes |  | The new data. |

Returns: `Object` The message.

### $.status(data, [delay])

Type: `method`

Sends a status of the node that received the message.

The same as `instance.status()`.

### $.on(name, callback)

Type: `method`

Listens to an event of the message.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The event, for example `end`. |
| `callback` | `Function` | yes |  | The function to call. |

The `end` event runs when the message and all the copies sent from it have ended. `$.once()` listens once and `$.off()` stops listening.

Example: Know when the flow is finished
```js
$.on('end', function() {
	instance.status('finished');
});
$.send('output');
```
