How to use the consul function in consul

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

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<Record<string, any>> {
  const values = await consul.kv.get<any[]>({
    key,
    recurse: true
  })
  return values.reduce((acc, value) => {
    const { Key: k, Value: v } = value

consul

Consul client

MIT
Latest version published 28 days ago

Package Health Score

78 / 100
Full package analysis

Popular consul functions

Similar packages