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-depot

v0.0.1

Published

mount Express sub-apps and middleware from a directory listing

Downloads

7

Readme

Express-Depot

Easily mount Express sub-applications and other middleware, from a directory listing.

Express-Depot allows you to create a plugin-like system for your Express applications. It will take a listing of folders (from a "parent" or "dispatch") folder, require each of the folders and mount the resulting sub-app or middleware as an enpoint in your Express application.

This is useful for Express apps that need to load third party or external plugins and services.

Getting Started

Install it:

npm install --save express-depot

Then in your Express app, run the dispatch method to load a complete list of directories from your "dispatch" folder, providing a base mount point for all of the sub-apps and other middleware to be mounted.

var express = require("express");
var path = require("path");
var depot = require("express-depot");

// ...

var app = express();

// ...

var dispatchFolder = path.join(__dirName, "dispatch");
depot.dispatch(app, "/plugins", dispatchFolder);

Creating Sub-Apps and Middleware To Dispatch

In your file system, create a folder called "dispatch" (as noted in the dispatchFolder variable, above). In this folder, create a single sub-directory for each sub-app or middleware that you wish to load.

Each folder should have an index.js file that exports valid Express middleware, (including a complete Express application object).

For example:

| dispatch/
| - cool-thing/
| - - index.js
| - whatever/
| - - index.js
| - - routes.js
| - - views/
| - - - index.jade

When you run the dispatcher, both cool-thing and whatever will be required and mounted into your parent Express app, using their folder name as the end-point.

If you dispatch to a /plugins folder, for example:

depot.dispatch(app, "/plugins", dispatchFolder);

You will create the following URI endpoints on your app:

  • /plugins/cool-thing
  • /plugins/whatever

From there, the URI and endpoint structure is determined by your middleware.

Demo App

For a quick demo of how this works with an Express Router or complete Express Sub-App, see the demo folder.

Run the demo app:

  • cd demo
  • npm install
  • node bin/wwww

Now open localhost:3000 to view the demo app and see the plugin end-points.

Be sure to examine the plugins folder in the demo to see how simple the middleware / sub-app exports can be.

Legal Junk

Copyright ©2016 Muted Solutions, LLC. All Rights Reserved.

Distributed under MIT license.