You're viewing **Apigee Edge** documentation.  
[Go to the
**Apigee X** documentation](http://cloud.google.com/apigee/docs/api-platform/cache/key-value-maps). info

> [!WARNING]
> **Private Cloud Deprecation Notice:**
>
> **Support for [Node.js](https://docs.apigee.com/api-platform/nodejs/overview-nodejs-apigee-edge) proxies
> and [secure vaults](https://docs.apigee.com/api-platform/nodejs/using-secure-store)**
>
> Since 2013, Apigee has supported the
> [use of Node.js proxies within Apigee
> Edge](https://www.programmableweb.com/news/apigee-api-platform-now-supports-node.js-allowing-developers-to-build-highly-customized-apis-and-apps/brief/2013/10/25) through the use of [Trireme](https://github.com/apigee/trireme), which enables you to run your Node.js code
> within Apigee Edge for Private Cloud and expose it as an API.
>
>
> Apigee recommends Private Cloud customers take the following steps:
>
> - Migrate data in secure vaults to [Encrypted Key Value Maps](https://docs.apigee.com/api-platform/cache/key-value-maps#aboutencrypted) (KVM) to access sensitive data from an API proxy.
> - Migrate Trireme (Node.js) based API proxies to a native Node.js environment outside of Apigee.
>
>
> See also [Apigee deprecations and retirements](https://docs.apigee.com/release/deprecated-features).

> [!WARNING]
> **Public Cloud Retired feature:** The traditional, Trireme-based
> Node.js support on Apigee Edge Cloud is retired and, by extension,
> [apigee-access](https://docs.apigee.com/api-platform/nodejs/using-apigee-access) is also
> retired because it is only used in Trireme-based Node.js applications deployed on Apigee Edge.
> Trireme-based Node.js was retired on October 10, 2019. See
> [Trireme-based Node.js End of Life](https://docs.apigee.com/release/notes/trireme-nodejs-eol).

You can use the `apigee-access` module to get Edge key value map (KVM)
data from within a Node.js application. This method of KVM retrieval is an alternative to using
the [Key Value Map
Operations policy](https://docs.apigee.com/api-platform/reference/policies/key-value-map-operations-policy) to retrieve KVM data in an API proxy flow.

KVMs provide long-term persistence of arbitrary key/value pairs that you can retrieve at
runtime. For example, you can store quota values, OAuth access token expiration values, and OAuth
refresh token expiration values in a KVM for each deployment environment, then retrieve the
values in your code.

You can create a KVM at one of three scopes: `organization`,
`environment`, and `apiproxy`. For example, if you create a KVM at the
apiproxy scope for the "foo" proxy, only the "foo" proxy can access the KVM; or if you create a
KVM at the "test" environment scope, all API proxies deployed in an organization's "test"
environment can access the KVM, but none of the proxies deployed in the "prod" environment can
access it.

After you create a KVM with the management API, management UI, or the Key Value Map Operations
policy (see [Long-term
persistence caching](https://docs.apigee.com/api-platform/cache/persistence-tools#longtermpersistenceofkeyvaluedata)), use the functions here to retrieve the data.

For a great KVM pattern, see [A pattern for caching KVM values](https://discuss.google.dev/t/a-pattern-for-caching-kvm-values/17117).

For an introduction to the `apigee-access` module and its other features,
see [Using the apigee-access
module](https://docs.apigee.com/api-platform/nodejs/using-apigee-access).

## Methods

The following methods work on both encrypted and unencrypted KVMs.

- [getKeyValueMap()](https://docs.apigee.com/api-platform/nodejs/accessing-key-value-maps-nodejs#getKeyValueMap)
- [getKeys()](https://docs.apigee.com/api-platform/nodejs/accessing-key-value-maps-nodejs#getKeys)
- [get()](https://docs.apigee.com/api-platform/nodejs/accessing-key-value-maps-nodejs#get)

*** ** * ** ***

### getKeyValueMap

```javascript
var kvm = apigee.getKeyValueMap('kvm_name', 'scope');
var kvm = apigee.getKeyValueMap('kvm_name', 'api', 'proxy_name');
```

Retrieves a KVM at a particular scope (organization, environment, api, or revision). After the
KVM object is returned, use the `getKeys` and `get` functions to return the
key names or a specific key value.

**Parameters:**

- ***kvm_name*** - The name of the KVM to access.
- ***scope*** - The scope of the KVM. One of `organization`, `environment,
  api,` or `revision`.
- ***proxy_name*** - For a ***scope*** of api only, the name of the API proxy.

**Returns:**

A KVM object.

**Example:**

```javascript
var apigee = require('apigee-access');
var kvm = apigee.getKeyValueMap('my_kvm', 'environment');
```

If you set ***scope*** to api then a third parameter is required -
the name of the API proxy. For example:

```javascript
var kvm = apigee.getKeyValueMap('my_kvm', 'api', 'myApiProxy');
```

*** ** * ** ***

### getKeys

`var kvmKeys =
apigee.getKeys(function(err, keys_array);`  

Returns an array containing the names of all keys in the KVM.

**Parameters:**

- ***`callback`*** : (Required) The callback function uses two parameters:
  - An Error object if the operation fails.
  - An object (`keys_array` in the example above) that represents the array of KVM key names.

**Returns:**

An array of KVM key names.

**Example:**

```javascript
var apigee = require('apigee-access');
var kvm = apigee.getKeyValueMap('my_kvm', 'environment');
  kvm.getKeys(function(err, keys_array) {
    // use the array of key names here
});
```

*** ** * ** ***

### get

`kvm.get('key', function(err,
key_value));`  

Gets the value of a KVM key.

**Parameters:**

- ***`key`***: (Required) A string that uniquely identifies
  the item in the cache.

- ***`callback`***: (Required) The callback function uses two
  parameters:

  - An Error object if the operation fails.
  - The object containing the KVM key value as a String.

**Example:**

```javascript
var apigee = require('apigee-access');
var kvm = apigee.getKeyValueMap('my_kvm', 'environment');
  kvm.get('foo_key', function(err, key_value) {
    // Use the key value here. For example the following assigns the value
    // to a 'kvmvalue' variable in the response, which can be used by policies:
      apigee.setVariable(response, 'kvmvalue', key_value);
});
```