JSPM

  • Created
  • Published
  • Downloads 14097
  • Score
    100M100P100Q158272F
  • License LGPL-3.0-or-later

Node.js client for the HashiCorp's Vault API

Package Exports

  • @litehex/node-vault

Readme

node-vault

A Javascript client for the HTTP API of HashiCorp's vault with a focus on ease of use.

npm install @litehex/node-vault

Usage

Init and unseal vault
import { Client } from '@litehex/node-vault';

// Get a new instance of the client
const vc = new Client({
  apiVersion: 'v1', // default
  endpoint: 'http://127.0.0.1:8200', // default
  token: 'hv.xxxxxxxxxxxxxxxxxxxxx' // Optional incase of you want to initialize the vault
});

// Init vault
vc.init({ secret_shares: 1, secret_threshold: 1 }).then((res) => {
  const { keys, root_token } = res;
  vc.token = root_token;
  // Unseal vault
  vc.unseal({ secret_shares: 1, key: keys[0] });
});
Write, read and delete secrets
vc.write({ path: 'secret/hello', data: { foo: 'bar' } }).then(() => {
  vc.read({ path: 'secret/hello' }).then(({ data }) => {
    console.log(data); // { foo: 'bar' }
  });
});

vc.delete({ path: 'secret/hello' });

Docs

Examples

Using a proxy or having the ability to modify the outgoing request.
import { Client } from '@litehex/node-vault';
import { ProxyAgent } from 'undici';

const agent = new ProxyAgent('http://localhost:8080');

const vc = new Client({
  // ... other params
  request: {
    dispatcher: agent,
    headers: {
      'X-Custom-Header': 'value'
    }
  }
});

Credits

This project is inspired by kr1sp1n/node-vault, and thanks to the contributors for their efforts.

License

This project is licensed under the GPLv3 License - see the LICENSE file for details