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

suspend-express

v0.1.0

Published

Write simpler, cleaner express routes using generators and suspend.

Downloads

8

Readme

suspend-express

Write simpler, cleaner express middleware using generators and suspend.

suspend-express is built for express 4 and requires Node v0.11.3+.

Quick Example

var express = require('express'),
    app = require('suspend-express').patch(express());

app.get('/users/:username', function*(req, res, next) {
    res.json(yield UserModel.find({ username: req.params.username }));
});

app.listen(3000);

Note: Generators are a new feature in ES6 and are still hidden behind the --harmony-generators (or the more general --harmony) flag in V8:

$ node --harmony-generators app.js

Installation

$ npm install suspend-express

Documentation

Overview

How it Works

suspend-express works by patching a given express app or router, allowing it to transparently (to express) wrap generator functions with suspend. The patched express app or router remains 100% compatible with its preexisting API; the only difference is that it can now accept generator functions in all the most useful places. For a deeper look at how it actually patches express applications, please check out the source.

Features

suspend-express is designed to enable generator functions within express' existing API, and then gets out of the way.

At present, the following express APIs are supported:

The entire API surface is well tested, with over a 3-to-1 ratio of tests cases to lines of code (that's just a fun stat, so I had to throw it in). Please do report any issues, however!

Limitations

While generator functions are enabled in most of the obvious places, you should be aware that they are not enabled in app.param(fn) or router.param(fn) (they are, however, supported when the name parameter is provided, as in app.param(name, fn*).

API

.patch(app|router)

Accepts an express application or router instance and performs the necessary patching to enable generator functions. The return value is the patched application.

Example:

var express = require('express'),
    app = require('suspend-express').patch(express());

Example:

var express = require('express'),
    router = require('suspend-express').patch(express.Router());

.suspend

A reference to the same instance of suspend being used by suspend-express. This reference should be used, as mixing with another copy of suspend may result in unexpected behavior.

Example:

var express = require('express'),
    se = require('suspend-express'),
    app = se.patch(express()),
    suspend = se.suspend;

app.get('/slow', function*() {
    yield setTimeout(suspend.resume(), 5000);
    res.send('Slow enough for you?');
});

Please note that since I maintain the suspend library as well, I can offer the following assurances:

  • suspend-express will be kept up-to-date with suspend.
  • The semantic versioning of suspend-express will account for any API developments of suspend as well.

License

The MIT License (MIT)

Copyright (c) 2014 Jeremy Martin

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.