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

express-discover

v1.0.2

Published

Allows connected Express applications to discover each other without configuration.

Downloads

13

Readme

express-discover

npm David Build Status

Allows connected Express applications to discover each other without configuration.

Install

Install from NPM

npm install express-discover -S

And import into your project

import registerService from "express-discover";
const registerService = require("express-discover");

Usage

The default exported method sets up an Express app to be used in a middleware network, such that each Express app is discoverable by name. The registerService method should be called on all Express applications that need to be discovered.

const mainapp = express();
registerService(mainapp, "main");

const authapp = express();
registerService(authapp, "auth");

Once all the apps have been registered, they need to be connected. This done very simply by using the middleware. As long as all the middleware have a shared root Express app, they can discover one another, even if they are deeply buried in many other Express apps.

// use just like you normally would
mainapp.use("/auth", authapp);

// now main and auth can find each other!
authapp.discover("main") === mainapp; // true
mainapp.discoverPath("auth") === "/auth"; // true

API

registerService( app, name [, backupPaths ] )

The default exported function that setups an app to be discovered.

  • app (Express App, required) - The application to make discoverable. Discovery API functions will be attached this app as well.
  • name (String, required) - The name of the application. It is recommended to make this value unique. When discovering apps, the first app with the specified name is returned.
  • backupPaths (Object) - An object of service names to string paths. This is used by app.discoverPath() when an app can't be found.

app.discover( name )

Returns the first discoverable app with name.

  • name (String, required) - The name of the app you are attempting to discover. This should match what was given to registerService().

app.discoverPath( name [, params ] )

Returns the full URL path to the first discoverable app with name. Since this uses app.path(), it has the side effect of returning application mount path literals. To combat this issue, you can pass an object of params to values, to fill in Express path segments like /:param.

  • name (String, required) - The name of the app you are attempting to get the URL for. This should match what was given to registerService().
  • params (Object) - An object of URL parameters to fill in.