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

# Instance reference

> The handlers, methods and properties of a node in the server code.

The instance is one node of the component. `exports.make` receives it, and you define its handlers there:

```js
exports.make = function(instance, config) {

	instance.message = function($) {
		$.send('output');
	};

	instance.close = function() {
	};

};
```

Entries of type **event** are functions that you define and Flow calls. Entries of type **method** are functions that Flow provides.

## API

### instance.message = function($) {}

Type: `event`

Receives every message that arrives on any input.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `$` | `Object` | yes |  | The message. See [Message reference](../message-api/). |

Each message must be sent on with `$.send()` or ended with `$.destroy()`. An exception thrown here ends the message.

Example: Forward the data in capital letters
```js
instance.message = function($) {
	$.send('output', String($.data).toUpperCase());
};
```

### instance.message_second = function($) {}

Type: `event`

Receives the messages of one input.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `$` | `Object` | yes |  | The message. |

The name is `message_` followed by the id of the input. When `instance.message` is also defined, Flow calls this handler first and then `instance.message` with the same message.

### instance.configure = function() {}

Type: `event`

Runs after the configuration of the node has changed.

Flow calls it when the user applies new settings and after `instance.reconfigure()`. It does not run when the node is created, so call it at the end of `exports.make`.

### instance.trigger = function(msg) {}

Type: `event`

Runs when the user selects the trigger button of the node.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `msg` | `Object` | yes |  | The request from the designer. |

A `<button name="trigger">` in the body, or `exports.trigger(data)` in the browser script, calls it. For a button, `msg.data` holds its `data-data` attribute. For `exports.trigger(obj)`, `msg` holds the keys of `obj`.

### instance.close = function() {}

Type: `event`

Runs when the node stops.

Flow calls it when the node is removed from the design and when the component changes. Stop timers and close connections here.

### instance.variables = function(variables) {}

Type: `event`

Runs when the variables of the FlowStream change.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `variables` | `Object` | yes |  | The new variables of the FlowStream. |

### instance.variables2 = function(variables) {}

Type: `event`

Runs when the global variables change.

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

### instance.pause = function(is) {}

Type: `event`

Runs when the FlowStream is paused or resumed.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `is` | `Boolean` | yes |  | `true` when paused, `false` when resumed. |

While the FlowStream is paused, Flow delivers no messages.

### instance.service = function(minutes) {}

Type: `event`

Runs once a minute.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `minutes` | `Number` | yes |  | The number of minutes since the FlowStream started. |

### instance.call = function(data, callback) {}

Type: `event`

Answers a call from the browser script of this node.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `data` | `Object` | yes |  | The data from the browser. |
| `callback` | `Function` | yes |  | Call it with the answer. |

The browser script calls it with `exports.call(data, callback)`, for example to load a list for the settings form.

Example: Answer a call
```js
instance.call = function(data, callback) {
	callback({ id: instance.id });
};
```

### instance.send(output, data)

Type: `method`

Starts a new message on an output.

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

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

Use it in components that start messages, such as triggers and timers. Without `output`, the message goes to every output that has a connection.

Example: Send the current date
```js
instance.send('output', { ts: new Date() });
```

### instance.newmessage(data)

Type: `method`

Creates a new message without sending it.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `data` | `Object` | no |  | The data of the message. |

Returns: `Object` The message.

Send it later with `msg.send(output)`. The **Route** component creates a message for each HTTP request this way and stores the request in `msg.refs`.

Example: Create and send a message
```js
var msg = instance.newmessage({ name: 'Jane' });
msg.send('output');
```

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

Type: `method`

Sends a status to the designer.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `data` | `Object` | yes |  | Any data, for example `{ count: 12 }`. |
| `delay` | `Number` | no |  | Waits this many milliseconds and then sends the last status, so that many quick calls send one status. |

The designer keeps the last status of each node and shows it through `$STATUS` in the body. See [Status and the look of the node](../status-and-look/).

Example: Count messages
```js
status.count++;
instance.status(status, 500);
```

### instance.activity(key, name, progress)

Type: `method`

Shows the progress of a task under Activities in the designer.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `key` | `String` | yes |  | An id of the task. |
| `name` | `String` | yes |  | The text of the line. |
| `progress` | `Number` | no |  | The progress from 0 to 100. |

The line disappears when `progress` is `100` or `name` is empty.

Example: Show progress
```js
instance.activity('import', 'Importing orders', 50);
```

### instance.throw(error)

Type: `method`

Reports an error to the designer.

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

The FlowStream keeps its last 10 errors, and the designer shows their number under **Errors**. See [Errors and logging](../errors-and-logging/).

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

Type: `method`

Fills in the variables of a text.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `text` | `String` | yes |  | The text with keys in braces. |
| `data` | `Object` | no |  | Values for keys that are not variables. |

Returns: `String` The text with the values.

Replaces each `{key}` with the FlowStream variable, the global variable or the secret of that name, `{hostname}` with the address of the FlowStream, and other keys from `data`. Keys that are not found stay as they are. See [Variables in components](../variables/).

Example: Fill in a variable
```js
instance.replace('{welcome}, Jane!');
// Good morning, Jane!
```

### instance.reconfigure(config)

Type: `method`

Changes keys of the configuration from code.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `config` | `Object` | yes |  | The keys to change. |

Merges the keys into the configuration, calls `instance.configure`, sends the configuration to the designer and saves the FlowStream.

Example: Turn on a setting
```js
instance.reconfigure({ uppercase: true });
```

### instance.save()

Type: `method`

Saves the node after you changed its inputs, outputs or configuration in code.

The designer redraws the node.

Example: Two outputs from the settings
```js
instance.outputs = [{ id: 'output', name: 'Output #1' }, { id: 'output2', name: 'Output #2' }];
instance.save();
```

### instance.id

Type: `property`

The id of the node in the design.

### instance.component

Type: `property`

The id of the component.

### instance.config

Type: `property`

The configuration of the node, the same object as `config` in `exports.make`.

### instance.outputs

Type: `property`

Outputs of this node that replace `exports.outputs`.

Set it and call `instance.save()`. `instance.inputs` works the same way for inputs.

### instance.main

Type: `property`

The FlowStream that runs the node.

`instance.main.id` is its id, `instance.main.variables` its variables and `instance.main.variables2` the global variables.

### instance.env

Type: `property`

The environment of Flow: `dev`, `test` or `prod`.

See [Environments](/flow/11-1/guides/environments/).
