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

@adastradev/serverless-discovery-sdk

v3.0.4

Published

Serverless Service Discovery API

Downloads

6,711

Readme

serverless-discovery-sdk-js

npm license The last serverless micro-service you'll ever wonder how to find

The AWS Serverless Discovery SDK interacts with a discovery microservice to discover endpoints for micro-services written for a serverless architecture. This is similar to clustered services such as Consul or ZooKeeper, but without the concept of instances or nodes that must be monitored for online state. This library is designed to support use both on the server side (for service-to-service lookups) and on the browser/client side.

This project contains the Typescript/Javascript bindings for the discovery service; Other bindings can be found in the AdAstraDev organization on GitHub

Installation

npm install @adastradev/serverless-discovery-sdk

Usage

Service/Cloud Dependencies

Semver versioning is supported by the discovery service 1.1.x. Pass a semver compatible value in the lookupService call to receive the newest compatible matching version. Services and their desired versions can also be specified in the cloudDependencies field of package.json.

{
  "cloudDependencies": {
    "service1": "1.x",
    "service2": "^1.2.8-testbranch", // A pre-release version for development purposes
    "service3": "3.x.x"
  }
}

Version Postfix values

In some testing environments, it can be useful to modify the lookup version to avoid collision with a production environment. If the VERSION_POSTFIX environment variable at runtime, it will always append this to the version of a lookup call.

If you are looking up services which are highly coupled or are not well isolated, and using them for system tests, you should:

  • Set the VERSION_POSTFIX environment variable set to -staging
  • Pass the environment variable through to the runtime where lookups are happening (lambda, docker, etc.)

If there is a lookup for serviceA, version 1.1.0, it will instead only talk to 1.1.0-staging. All lookup calls will follow a similar pattern while the environment variable is present.

TL;DR: If you are looking up services which are not well isolated, and rely on a staging environment to avoid operations on prod databases/resources, add the following to your pipeline in a staging deployment/testing step.

bitbucket-pipelines.yml:

- export VERSION_POSTFIX='-staging'
# Deployment steps follow...

serverless.yml

provider:
  environment:
    VERSION_POSTFIX: ${env:VERSION_POSTFIX, ''}

Code Example

I recommend setting up a utility function to handle construction of the SDK, and the lookup call - see below example.

import { DiscoverySdk } from '@adastradev/serverless-discovery-sdk';

export default async function lookup(serviceName) {

  const sdk = new DiscoverySdk(
    process.env.DISCOVERY_SERVICE_URL,
    process.env.DISCOVERY_SERVICE_REGION,
    // Non-versioned services will default to lookup via this stage
    process.env.DEFAULT_STAGE,
    undefined,
    // Create map of cloudDependencies from package.json
    new Map(Object.entries(require('../path/to/package.json')['cloudDependencies'])),
  );

  const endpoints = await sdk.lookupService(
    serviceName
  );

  return endpoints[0];

}