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

@hapiness/consul

v1.0.2

Published

Hapiness module for consul

Downloads

4

Readme

Consul Module

Consul module for the Hapiness framework.

To get started with consul, you can begin with having a look at the consul official documentation

Table of contents

Using your module inside Hapiness application

yarn or npm it in your package.json

$ npm install --save @hapiness/core @hapiness/consul rxjs

or

$ yarn add @hapiness/core @hapiness/consul rxjs
"dependencies": {
    "@hapiness/consul": "^1.0.0",
    "@hapiness/core": "^1.5.1",
    "rxjs": "^5.5.7",
    //...
}
//...

Using Consul inside your hapiness application

Import the module

You need to include ConsulModule in the imports section of your module definition.


@HapinessModule(
    {
        version: '1.0.0',
        declarations: [/* your declarations */],
        providers: [/* your providers */],
        exports: [/* your exports */],
        imports: [ConsulModule /* other modules */]
    }
)
export class MyModule { /* ... */ }

Bootstrap the extension

You need to inject the extension in bootstrap using setConfig to instantiate the module.

The config properties allowed for the extensions are defined like this:


export interface HapinessConsulClientOptions {
    scheme?: string;
    host?: string;
    port?: string;
    defaults?: {
        consistent?: boolean;
        dc?: string;
        stale?: boolean;
        token?: string;
        wait?: string;
        wan?: boolean;
        ctx?: NodeJS.EventEmitter;
        timeout?: number;
    };
    ca?: string;
    baseUrl?: string;
}

Then just do like this:

Hapiness
    .bootstrap(
        MyModule,
        [
            ConsulExt.setConfig({
                /* Put your config here */
            })
        ])
    .catch(err => done(err));

Use the exposed service

This library is in fact a wrapper of the famous consul node library but wrap all its functions to returns rxjs Observable

You can see the doc by clicking here

We provide a wrapper called ConsulService exposing a clientgetter that will allow you to access the consul client.


class FooProvider {

    constructor(private _consul: ConsulService) {}

    bar(): Observable<string> {
        // Getting a key from the KV client of consul
    	return this._consul.client.kv.get('hello');
    }


    acquireLock(): void {
        // Create a consul lock
        const lock = this._consul.client.lock({ key: 'test' });

        // Listen to lock events
        lock.on('acquire', () => {
            console.log('lock acquired'));
            lock.release();
        });
        lock.on('release', () => console.log('lock released'));
        lock.on('error', () => console.log('lock error:', err));
        lock.on('end', (err) => console.log('lock released or there was a permanent failure'));

        // Acquire the lock
        lock.acquire();
    }

}

Back to top

Contributing

To set up your development environment:

  1. clone the repo to your workspace,
  2. in the shell cd to the main folder,
  3. hit npm or yarn install,
  4. run npm or yarn run test.
    • It will lint the code and execute all tests.
    • The test coverage report can be viewed from ./coverage/lcov-report/index.html.

Back to top

Maintainers

Back to top

License

Copyright (c) 2018 Hapiness Licensed under the MIT license.

Back to top