How to use consul - 1 common examples

To help you get started, we’ve selected a few consul examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shfshanyue / apollo-server-starter / lib / consul.ts View on Github external
import _ from 'lodash'
import Consul from 'consul'
import { host, port } from '../config/consul'

function parse (s: string) {
  try {
    return JSON.parse(s)
  } catch {
    return s
  }
}

export const consul = Consul({
  promisify: true,
  host,
  port
})

/**
 * @param  {string} key redis
 * @returns Promise { redis: { port: 6379, host: 'redis.xiange.tech' }}
 */
export async function get (key: string): Promise> {
  const values = await consul.kv.get({
    key,
    recurse: true
  })
  return values.reduce((acc, value) => {
    const { Key: k, Value: v } = value

consul

Consul client

MIT
Latest version published 1 year ago

Package Health Score

57 / 100
Full package analysis

Popular consul functions