Yemma-Discoveryis a thin layer to help you manage your nodes in a micro-services architectures maintained in a Registryby Yemma

Either your application represent a micro-service, either your application is a Gateway and wants to access a node with some specifications.

  1. Install Yemma-Discovery
npm i --save yemma-discovery
  1. To register yourself as a service

Yemma-Discoveryautomatically register itself as a service as soon as it is instanciated.

Before registering yourself, Yemma-Discoverywill look into some environment variables:

# Related to the registry
YEMMA_URI= #required information about where the registry is hosted
YEMMA_TOKEN=ytoken                  #since the registry is a yemma application it will verify each request with a token (set during yemma configuration)

# Related to the node itself
REALM=admin                          #required to tell the registry for which part of the business the node is responsible
PORT=3030                            #required also, the port where the node is listening
ACCESS_TOKEN=xF%eeT$mbS&             #required also, the secret used to ensure only trusted issuer can make requests                  #[optional] if the node is behind a proxy, you can set a host, if not, the registry will try to resolve the node'ip address during registration.
const DisoveryService = require('yemma-discovery');
new DiscoveryService(); // will automatically register the node to the registry

That's it, you are now discoverablefrom the registry.

You can disable this behavior by passing an option in the constructor. Meaning you don't have to set information related to the node itself.

const DisoveryService = require('yemma-discovery');
new DiscoveryService({ heartBeats: false }); // disable the heartbeat

2.1 Ensuring the request issuer is valid In a typical expressserver type you can use Yemma-Discovery to validate request issuers are allowed to access your API.

cons express = require('express');
const DisoveryService = require('yemma-discovery');

const server = express();
const ds = new DiscoveryService(); // will automatically register the node to the registry

server.use((req, res, next) => {
    const access_token = req.header('access-token');
        .then(() => next())
        .catch(() => res.status(403).send('invalid.issuer'));

server.get('/', (req, res) => res.send('hello, world'));
  1. Proxy request to registered instances.

If you develop a Gateway, it can be helpful to have a direct access to the registered nodes.

const DisoveryService = require('yemma-discovery');
const registry = new DiscoveryService({ heartBeats: false }); // disable the heartbeat

const express = require('express');
const server = express();


function proxy(req, res, next) {
    const components = req.originalUrl.split('/')
    const realm = components[1];

        .next({realm: realm})
        .then(instance => instance.request('/api/users'))
        .then(response => {
            res.headers = response.headers;
        .catch(response => {

console.log('Gateway listening on port 3000');




  • torrent-discovery

    Discover BitTorrent and WebTorrent peers torrentdiscovery travistravisimagetravisurl npmnpmimagenp...

    5 个月前
  • node-opcua-service-discovery

    pure nodejs OPCUA SDK module servicediscovery nodeopcuaservicediscovery CDN by jsDeliv...

    1 年前
  • node-opcua-server-discovery

    pure nodejs OPCUA SDK module serverdiscovery nodeopcuaserverdiscovery CDN by jsDelivr ...

    1 年前
  • hyperdiscovery

    Join the p2p swarm for hypercore and hyperdrive feeds. hyperdiscovery build status(https://travis...

    8 个月前
  • dns-discovery

    Discovery peers in a distributed system using regular dns and multicast dns. dnsdiscovery Discove...

    7 个月前
  • discovery-tsd

    Generates TypeScript declaration files from Google's Discovery API discoverytsd Generate TypeScr...

    5 个月前
  • discovery-swarm-web

    Abstracts away discoveryswarm interaction with WebRTC and a websocket gateway. discoveryswarmweb A...

    7 个月前
  • discovery-swarm-stream

    Proxy discovery over a stream Discovery Swarm Stream Alows clients to use discoverychannel(https:...

    6 个月前
  • discovery-swarm

    A network swarm that uses discoverychannel to find peers discoveryswarm A network swarm that uses...

    7 个月前
  • discovery-channel

    discover peers that have hashes using various kewl methods discoverychannel Search for a key acro...

    7 个月前


扫码加入 JavaScript 社区