---
title: Backend
summary: Class for dynamically creating new Fastly Backends.
url: https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/backend/class.Backend/
---

**Kind:** Class  
**Module:** [backend](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/backend/)  
**Package:** @fastly/js-compute 4.0.1  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/backend.d.ts#L305

Class for dynamically creating new [Fastly Backends](https://developer.fastly.com/reference/api/services/backend/).

**Note**: Dynamic backends are by default disabled at the Fastly service level.
Contact [Fastly Support](https://support.fastly.com/hc/en-us/requests/new?ticket_form_id=360000269711)
to request dynamic backends on Fastly Services.

To disable the usage of dynamic backends, see [enforceExplicitBackends](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/backend/fn.enforceExplicitBackends/).

````javascript
In this example an explicit Dynamic Backend is created and supplied to the fetch request, the response is then returned to the client.
```js
/// <reference types="@fastly/js-compute" />
import { Backend } from "fastly:backend";
async function app() {
  // For any request, return the fastly homepage -- without defining a backend!
  const backend = new Backend({
    name: 'fastly',
    target: 'fastly.com',
    hostOverride: "www.fastly.com",
    connectTimeout: 1000,
    firstByteTimeout: 15000,
    betweenBytesTimeout: 10000,
    useSSL: true,
    tlsMinVersion: 1.3,
    tlsMaxVersion: 1.3,
  });
  return fetch('https://www.fastly.com/', {
    backend // Here we are configuring this request to use the backend from above.
  });
}
addEventListener("fetch", event => event.respondWith(app(event)));
```
````

## Constructor

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/backend.d.ts#L322

```javascript
new Backend(configuration: BackendConfiguration)
```

Creates a new Backend instance.

**Note:** `Backend()` can only be constructed with `new`. Attempting to call it
without `new` throws a TypeError.

All optional generic options can have their defaults set via
[setDefaultDynamicBackendConfig](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/backend/fn.setDefaultDynamicBackendConfig/). This includes all configuration
options except for `name`, `target`, `hostOverride`, `sniHostname` and `grpc`.

**Parameters**

- `configuration`: `BackendConfiguration`

````javascript
Construct a new backend with all properties set to their default values:
```js
const myBackend = new Backend({ name: 'fastly', target: 'www.fastly.com'});
```
````

## Properties

### name

**Type:** `string`  
**Flags:** read-only, since 3.24.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/backend.d.ts#L343

The name of the backend.

```js
import { Backend } from "fastly:backend";
const backend = new Backend({
  name: "my-backend",
  target: "my-site.com",
});
console.log(backend.name); // "my-backend"
```

### isDynamic

**Type:** `boolean`  
**Flags:** read-only, since 3.24.0   
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/backend.d.ts#L349

Whether this backend was dynamically created by the running service.

### target

**Type:** `string`  
**Flags:** read-only, since 3.24.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/backend.d.ts#L354

The host target for the backend

### hostOverride

**Type:** `string`  
**Flags:** read-only, since 3.24.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/backend.d.ts#L361

The host header override defined for the backend.

See https://docs.fastly.com/en/guides/specifying-an-override-host for more information.

### port

**Type:** `number`  
**Flags:** read-only, since 3.24.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/backend.d.ts#L366

The backend port

### connectTimeout

**Type:** `number | null`  
**Flags:** read-only, since 3.24.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/backend.d.ts#L372

The connect timeout for the backend in milliseconds, if available.
When not set or in environments that do not support this property (such as Viceroy), `null` may be returned.

### firstByteTimeout

**Type:** `number | null`  
**Flags:** read-only, since 3.24.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/backend.d.ts#L378

The first byte timeout for the backend in milliseconds, if available.
When not set or in environments that do not support this property (such as Viceroy), `null` may be returned.

### betweenBytesTimeout

**Type:** `number | null`  
**Flags:** read-only, since 3.24.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/backend.d.ts#L384

The between bytes timeout for the backend in milliseconds, if available.
When not set or in environments that do not support this property (such as Viceroy), `null` may be returned.

### httpKeepaliveTime

**Type:** `number`  
**Flags:** read-only, since 3.24.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/backend.d.ts#L389

The HTTP keepalive time for the backend in milliseconds, or 0 if no keepalive is set.

### tcpKeepalive

**Type:** `null | { timeSecs: number | null; intervalSecs: number | null; probes: number | null }`  
**Flags:** read-only, since 3.24.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/backend.d.ts#L394

The TCP keepalive configuration, if TCP keepalive is enabled.

### isSSL

**Type:** `boolean`  
**Flags:** read-only, since 3.24.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/backend.d.ts#L412

Whether the backend is configured to use SSL.

### tlsMinVersion

**Type:** `1 | 1.1 | 1.2 | 1.3 | null`  
**Flags:** read-only, since 3.24.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/backend.d.ts#L418

The minimum TLS version number this backend will use.
When not used, or for environments that do not support this feature (such as Viceroy), `null` may be returned.

### tlsMaxversion

**Type:** `1 | 1.1 | 1.2 | 1.3 | null`  
**Flags:** read-only, since 3.24.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/backend.d.ts#L424

The maximum TLS version number this backend will use.
When not used, or for environments that do not support this feature (such as Viceroy), `null` may be returned.

## Methods

### exists

**Flags:** static  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/backend.d.ts#L474

```javascript
static exists(name: string): boolean
```

Returns a boolean indicating if a Backend with the given name exists or not.

**Parameters**

- `name`: `string`

**Returns**

`boolean`

### fromName

**Flags:** static  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/backend.d.ts#L480

```javascript
static fromName(name: string): Backend
```

Returns the Backend instance with the given name, if one exists. If one does not exist, an error is thrown.

**Parameters**

- `name`: `string`

**Returns**

`Backend`

### health

_Overload 1 of 2_

```javascript
health(): 'healthy' | 'unhealthy' | 'unknown'
```

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/backend.d.ts#L436

Returns a string representing the health of this backend.
Possible values are:

- "healthy" - The backend's health check has succeeded, indicating the backend is working as expected and should receive requests.
- "unhealthy" - The backend's health check has failed, indicating the backend is not working as expected and should not receive requests.
- "unknown" - The backend does not have a health check configured.

**Returns**

`'healthy' | 'unhealthy' | 'unknown'`

_Overload 2 of 2_

```javascript
static health(backend: Backend): 'healthy' | 'unhealthy' | 'unknown'
```

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/backend.d.ts#L493

> **DEPRECATED:** Use `backend.health()` (Backend.prototype.health) instead.

Returns a string representing the health of the given Backend instance.
Possible values are:

"healthy" - The backend's health check has succeeded, indicating the backend is working as expected and should receive requests.
"unhealthy" - The backend's health check has failed, indicating the backend is not working as expected and should not receive requests.
"unknown" - The backend does not have a health check configured.

**Parameters**

- `backend`: `Backend`

**Returns**

`'healthy' | 'unhealthy' | 'unknown'`

### toName

**Flags:** deprecated  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/backend.d.ts#L443

> **DEPRECATED:** Use `backend.name` instead.

```javascript
toName(): string
```

Returns the name associated with the Backend instance.

**Returns**

`string`

### toString

**Flags:** deprecated  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/backend.d.ts#L468

> **DEPRECATED:** Use `backend.name` instead.

```javascript
toString(): string
```

Returns the name associated with the Backend instance.

The Backend object overrides the `toString()` method of Object; it does not inherit
`Object.prototype.toString()`. For Backend values, the `toString` method returns the
name given to the Backend object during construction.

**Returns**

`string`

```js
import { Backend } from "fastly:backend";
const backend = new Backend({
  name: "my-backend",
  target: "my-site.com",
});
console.log(backend.toString()); // "my-backend"
```
