---
title: SecretStore
summary: Class for accessing a Fastly secret store.
url: https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/secret-store/class.SecretStore/
---

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

Class for accessing a [Fastly secret store](https://developer.fastly.com/reference/api/services/resources/secret-store/).

A secret store is a persistent, globally distributed store for secrets accessible to
Fastly Compute services during request processing.

**Note**: Can only be used when processing requests, not during build-time initialization.

````javascript
In this example we connect to a secret store named `'secrets'` and retrieve a secret
named `'cat-api-key'` to use in a request header.

```js
/// <reference types="@fastly/js-compute" />

import { SecretStore } from "fastly:secret-store";

async function app(event) {
  const secrets = new SecretStore('secrets')

  const catApiKey = await secrets.get('cat-api-key')

  return fetch('/api/cat', {
    headers: {
      'cat-api-key': catApiKey.plaintext()
    }
  })
}

addEventListener("fetch", (event) => event.respondWith(app(event)))
```
````

## Constructor

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

```javascript
new SecretStore(name: string)
```

Creates a new `SecretStore` object which interacts with the Fastly secret store named `name`.

**Parameters**

- `name`: `string`

  Name of the Fastly secret store to interact with. A name cannot be empty,
    longer than 255 characters, or contain characters other than letters, numbers, dashes
    (`-`), underscores (`_`), and periods (`.`).

**Throws**

- Throws `TypeError` if no secret store exists with the provided name, the name is empty,
  longer than 255 characters, or contains invalid characters.

## Methods

### fromBytes

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

```javascript
static fromBytes(bytes: ArrayBufferView | ArrayBuffer): SecretStoreEntry
```

Construct a local in-memory `SecretStoreEntry` from the provided bytes, useful for
passing bytes to APIs that only accept a `SecretStoreEntry`.

**Note**: This is not the recommended way to obtain secrets — use [get](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/secret-store/class.SecretStore/#method-get) instead.

**Parameters**

- `bytes`: `ArrayBufferView | ArrayBuffer` — The raw bytes to wrap as a `SecretStoreEntry`.

**Returns**

`SecretStoreEntry`

### get

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

```javascript
get(key: string): Promise<SecretStoreEntry | null>
```

Get the value associated with the key `key` in the secret store. If the key does not
exist, the returned `Promise` resolves with `null`.

**Parameters**

- `key`: `string`

  The key to retrieve. A key cannot be empty, longer than 255 characters, or
    contain characters other than letters, numbers, dashes (`-`), underscores (`_`), and
    periods (`.`).

**Returns**

`Promise<SecretStoreEntry | null>`

**Throws**

- Throws `TypeError` if the key is empty, longer than 255 characters, or contains
  invalid characters.
