GithubHelp home page GithubHelp logo

node-consul-kv's Introduction

cicd

consul-kv

A tiny NPM package providing a minimal Consul KV store client.

Using consul-kv

Instantiating:

const Consul = require('consul-kv');

const consul = new Consul({
  host: 'my-consul.com', // required
  token: 'my-acl-token', // optional
  tlsCert: '<your-cert>', // optional
  tlsKey: '<your-cert-key>', // optional
  ca: '<your-ca-cert>', // optional
  port: '8500', // optional; defaults to '8500'
  protocol: 'https', // optional; defaults to 'https'
});

Usage

Create or update a key:

const resp = await consul.set('my/key', 'my-key-value');

Read a key:

const result = await consul.get('my/key');

console.log(result.value); // the key's value; undefined if it doesn't exist
console.log(result.responseStatus); // the HTTP status code of the Consul response
console.log(result.responseBody); // the HTTP body of the Consul response

Read a the full subtree below a key (this adds a ?recurse query to the request, per Consul documentation):

const result = await consul.get('my/key', { recurse: true });

console.log(result); // the entire 'my/key' subtree
console.log(result.responseStatus); // the HTTP status code of the Consul response
console.log(result.responseBody); // the HTTP body of the Consul response

Delete a key:

const resp = await consul.delete('my/key');

Bonus: issue your own requests & get the raw response:

const resp = await consul.request({
  key: 'my/key',
  body: 'my-value-or-optional-request-body',
  method: 'put'
});

Development

Install dependencies & run unit tests:

npm install
npm test

Run end-to-end tests against a local Consul using docker-compose:

docker-compose up --detach
npm run test:e2e

node-consul-kv's People

Contributors

mdb avatar nao23 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

node-consul-kv's Issues

Create a suite of integration tests

Currently, node-consul-kv has a suite of tests that run against mocked requests to Consul. It would also be useful, arguably, to author a suite of "live" integration tests that run against an actual docker-compose'd Consul on localhost, similar to the technique employed by vinyldns/vinyldns-js, for example.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.