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

yemma-discovery

v2.3.3

Published

[![Build Status](https://travis-ci.org/Digipolitan/yemma-discovery.svg?branch=master)](https://travis-ci.org/Digipolitan/yemma-discovery) [![Test Coverage](https://codeclimate.com/github/Digipolitan/yemma-discovery/badges/coverage.svg)](https://codeclimat

Downloads

43

Readme

Yemma-Discovery

Build Status Test Coverage

Yemma-Discovery is a thin layer to help you manage your nodes in a micro-services architectures maintained in a Registry by 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-Discovery automatically register itself as a service as soon as it is instanciated.

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

# Related to the registry
YEMMA_URI=http://localhost.com:9000 #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
HOST=customHost.org                  #[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 discoverable from 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 express server 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');
    ds.validateIssuer(access_token);
        .then(() => next())
        .catch(() => res.status(403).send('invalid.issuer'));
});

server.get('/', (req, res) => res.send('hello, world'));
server.listen(3000);
  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();

server.use(proxy);

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

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

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