Vault Module

Vault module provides access to the secrets stored in your secret store. Vault only allows retrieval of the unencrypted value of your secrets. It does not allow storing new secrets in the secret store or modifying the value of existing secrets. In order to store new secrets please go to the Functions editor page and look for MY SECRETS.

The Vault module is made available with the following require statement:

const vault = require('vault');

Vault module provides a single method: get(<secretKey>). Consistent with the other Functions modules, this method returns a Promise.

The following example shows how to retrieve a securely stored API key from the secret store in order to make an authenticated XHR request to another service with it.

Note that the following Function is of OnRequest type.

export default (request, response) => {
const xhr = require('xhr');
const vault = require('vault');

return vault.get("myApiKey").then((apiKey) => {
const http_options = {
"method": "GET",
"headers": {
"API_KEY": apiKey
return xhr.fetch("", http_options).then((resp) => {
return response.send("OK");
show all 17 lines
Functions support

Functions provides a rich set of tools, and this documentation does not cover all of the potential situations you may encounter. If you need help with a situation not covered by the documentation, please contact PubNub Support

Last updated on
On this page