npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-vault-js

v1.2.0

Published

Pure Javascript Vault Client

Downloads

1,336

Readme

Vault Node.JS Client

A Vault Client implemented in pure javascript (because I strongly dislike CoffeeScript) for https://github.com/hashicorp/vault.

The original code was from https://github.com/kr1sp1n/node-vault, thank you to @kr1sp1n for the work. This code was compiled original from CoffeeScript and then cleaned up and modified to use the debug and request library.

This library also no longer uses environment variables.

Install

npm install node-vault-js

Example

var Vault = require('node-vault-js');
var vault = new Vault({
  endpoint: 'https://vault.private.io:8200',
  token: access_token
});

vault.write('secret/hello', { value: 'world', lease: '1s' }, function(err, result) {
  if (err) {
    throw err
  }
  console.log('Wrote with response: ', result)

  vault.read('secret/hello', function(err, result) {
    if (err) {
      throw err
    }
    console.log('Read with response: ', result)

    vault.delete('secret/hello', function(err, result) {
    if (err) {
      throw err
    }
    console.log('Deleted with response: ', result)

    });
  });
});

Api

Vault([options])

This module exports a constructor which takes the following options:

  • apiVersion (String, optional) which api version to use, defaults to 'v1'
  • endpoint (String, optional) vault endpoint of format 'host:port', defaults to 'http://127.0.0.1:8200'
  • token (String, optional) cookie token, defaults to ''
  • requestOptions (Object, optional) extra request options, defaults to {}

Vault##write(path, data, cb)

Writes data to path.

Vault##read(path, cb)

Reads data from path.

Vault##delete(path, cb)

Deletes data stored at path.

Vault##help(path, cb)

Gets help for path.

Auth

Don't forget to authenticate with the vault server before you do any operations that need an access token. Here is an easy example using the request module.

  var url = require('url')
  var request = require('request')

  function authenticateVault (vaultURL, appId, userId, callback) {
    var vaultLogin = url.resolve(vaultURL, '/v1/auth/app-id/login')
    var opts = {
      url: vaultLogin,
      body: {
        app_id: appId,
        user_id: userId
      },
      json: true
    }
    request.post(opts, function (err, res, body) {
      if (err) {
        return callback(err)
      }

      callback(null, body.auth.client_token)
    })
  }

License

MIT