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

pomegranate-express

v1.1.0

Published

Provides an Express server, middleware layer, and route loader to the pomegranate framework.

Downloads

26

Readme

Pomegranate-Express

A Plugin bundle for the Pomegranate application framework. Pomegranate-Express bundles several easily configurable plugins that implement the Express framework.

Usage and Examples

Install

$ npm install --save pomegranate pomegranate-express
$ ./node_modules/.bin/pomegranate init -f . && ./node_modules/.bin/pomegranate build
$ node pom.js

Routing.

The Router plugin creates your route structure based on directory and module names. You can basically treat it exactly like an instance of Express Router because that is exactly what it is.

ex.

/* file ./routes/index.js */

module.exports = function(Router){

  //available at http://localhost:8080/
  Router.get('/', function(req, res, next){
    res.send('Hello from the index')
  })

  // Note: your route files must return
  // the factory instance of Router provided
  return Router
}

You can define named routes just as easily.

/* file ./routes/hello/index.js */

module.exports = function(Router){
  //available at http://localhost:8080/hello
  Router.get('/', function(req, res, next){
    res.send('Hello from a sub directory')
  })

  //available at http://localhost:8080/hello/world
  Router.get('/world', function(req, res, next){
    res.send('Hello from a named route')
  })
  return Router
}

Finally You can name your files if you have complex routes that you wish to segregate. These coexist with index files, so feel free to experiment with what works best for you.

/* file ./routes/hello/name.js */

module.exports = function(Router){
  //available at http://localhost:8080/hello/name/bob
  Router.get('/:name', function(req, res, next){
    res.send('Hello from a named file ' + req.params.name)
  })
  return Router
}

Middleware.

Obviously any Express application lives on its middleware stack. Pomegranate makes it easy to create, configure and load your middleware functions without a huge boilerplate file.

The Application Plugin creates a shared object that middleware functions can merge into, Later in the Pomegranate bootstrap process, the PreRouter and PostRouter plugins will use this object to mount your middleware. The BundleMiddleware plugin provides some stock functions, but you can easily override them by creating your own with the same name.

ex.

/* file ./plugins/MyMiddleware.js */

module.exports = {
  options: { //optional but preferred}
  metadata: {
    name: 'MyMiddleware',
    layer: 'dependencies'
    param: 'Middleware',
    type: 'merge'
  },
  plugin: {
    load: function(inject, loaded){

      /*
       * Create one or many middleware functions here, you can split them up into separate files if needed.
       */

      var myMiddlewares = {
       awesome: function(req, res, next){
          console.log('You are really awesome')
          next()
       }
     }

     /*
      * When you are ready, call loaded with your middlewares as the second param.
      * If something goes wrong, pass the error to the first param of loaded()
      */

     loaded(null, myMiddlewares)
    },
    start: function(done){
      done(null)
    }
    stop: function(done){
      done(null)
    }
  }
}

Included Plugins

Application

Provides the Express App, Express Router Factory and Middleware object.

Injector: Dynamic Adds a dynamic number of objects.
Injects: Service Express - Configurable instance of Express.
Injects: Factory Router - Provides instances of Express.Router() to define routes on.
Injects: Merge Middleware - An object spanning all of the middleware in a project.
Properties

| Name | Type | Default | Description | | --- | --- | --- | --- | | options | Object | | Plugin Options | | options.caseSensitiveRoutes | Boolean | false | | | options.mergeReqParams | Boolean | false | | | options.strictRouting | Boolean | false | |

BundledMiddleware

Provides Overrideable standard middleware.

Injector: Merge Merges all returned objects into the provided dep name.
Injects:: function Middleware - 404
Injects:: function Middleware - 500
Properties

| Name | Type | Description | | --- | --- | --- | | options | Object | This plugin has no options |

PreMiddleware

Configures the Express application and mounts all pre-route middleware.

Injector: None Adds nothing to the injector.
Properties

| Name | Type | Description | | --- | --- | --- | | options | Object | Plugin Options | | options.order | Array | Mount order of middleware functions. |

Router

Loads and mounts provided route definition files located in options.workDir

Injector: None Adds nothing to the injector.
Properties

| Name | Type | Default | Description | | --- | --- | --- | --- | | options | Object | | Plugin Options | | options.workDir | String | ./routes | Directory to load routes from. |

PostMiddleware

Configures the Express application and mounts all post-route middleware, including error handlers.

Injector: None Adds nothing to the injector.
Properties

| Name | Type | Default | Description | | --- | --- | --- | --- | | options | Object | | Plugin Options | | options.order | Array.<String> | '['404','500']' | Mount order of middleware functions. |

Launcher

Configures the Express application and mounts all pre-route middleware.

Injector: None Adds nothing to the injector.
Properties

| Name | Type | Default | Description | | --- | --- | --- | --- | | options | Object | | Plugin Options | | options.port | Number | 8080 | Port to bind server to. | | options.address | String | localhost | Address to bind server to. |

Bundled Middleware

404

Bundled 404 handler middleware

500