---
hide_title: false
hide_table_of_contents: false
pagination_next: null
pagination_prev: null
---
# `SecretStore()`

The **`SecretStore` constructor** lets you connect your Fastly Compute application to a Fastly 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.

## Syntax

```js
new SecretStore(name)
```

> **Note:** `SecretStore()` can only be constructed with `new`. Attempting to call it without `new` throws a [`TypeError`](../../globals/TypeError/TypeError.mdx).

### Parameters

- `name` _: string_
  - The Fastly Secret Store which should be associated with this SecretStore instance
  
### Return value

A new `SecretStore` object.

### Exceptions

- `TypeError`
  - Thrown if no Secret Store exists with the provided name
  - Thrown if the provided name is longer than 255 in length
  - Thrown if the provided name is an empty string
  - Thrown if the provided name contains characters other than letters, numbers, dashes (-), underscores (_), and periods (.)

## Examples

In this example we connect to a Secret Store named `'secrets'` and retrieve a secret named `'cat-api-key'` use the value 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)))

```
