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

spirit-express

v0.2.3

Published

use express middleware with spirit

Downloads

13

Readme

spirit-express

Wraps a Express (or Connect) middleware to make it compatible with spirit.

Wrapped Express (or Connect) middleware and spirit middleware can be used in conjunction with each other, it's not one or the other.

It is not meant to bring full Express API compatibility, but enough for most Express middleware to work, thus reducing extra overhead from Express API that normally are never used.

Build Status Coverage Status

Usage

npm install spirit-express

const compat = require("spirit-express")
compat(express_middleware) // use anywhere that supports spirit middleware

For specific examples, see the examples dir

NOTE: it is almost always better to use a "native" spirit middleware over using this module to wrap a Express middleware (if one exists).

Supported Express middleware

Note, this list is not exhaustive, but the following have been tested:

  • passport
  • body-parser
  • cookie-parser
  • multer
  • express-session
  • webpack-dev-middleware & webpack-hot-middleware

Express error handling middleware (err, req, res, next) are not supported on purpose. Instead handle errors the conventional way by using Promise catch. Note that next(err) is supported and will just throw the err.

Doc

This module wraps a Express middleware so it runs like a spirit middleware.

It also makes changes to how a request and response are handled.

request

The normal request object in spirit is copied over to the original req object from node (http.IncomingRequest). This "req" object is what is passed to Express middleware and spirit middleware.

So the req object replaces the spirit request throughout once a Express middleware is used.

Note that the req does not support any Express related req API, which in most cases is not needed. Most Express middleware avoid using the Express req API so they can be compatible with Connect.

response

The res object passed to Express middleware is not a node res object. But instead, it's a object that mocks certain common properties and methods that exist on a node and Express res object.

In spirit, middleware flow once on input, and once on output (bidirectional). This is in contrast to the Express model where middleware only go one way. To make it compatible with the spirit model, all changes a Express middleware would normally do on the res object are stored and accumulated.

The stored changes will be set once by the first Express middleware that is encountered on flow back (which would be the last Express middleware, depending on how you think about it).

The above is only true when a Express middleware makes partial changes to the res object. If a Express middleware terminates (because of res.end or res.writeHead) then it would not continue moving forward, but instead immediately return a response.

The following Express methods are supported:

  • res.redirect
  • res.send