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

v0.5.3

Published

Express monkey-patch to support Streamline syntax.

Downloads

69

Readme

Travis build status

Express-Streamline

Patch for Express to add support for Streamline syntax in Express apps.

Supports Express 2 through 5.

Example

var express = require('express-streamline');
var app = express();

// ...

app.use(function (req, res, _) {
    if (req.session.userId) {
        req.currentUser = User.getById(req.session.userId, _);
    }
});

// ...

app.get('/photos', function (req, res, _) {
    var photos = req.currentUser.getPhotos(_);
    res.render('photos', {
        photos: photos,
    });
});

Installation

npm install express-streamline --save

Usage

You can either require() Express normally and then patch it:

var express = require('express');
require('express-streamline');

Or just require() this module, which returns the patched Express for convenience:

var express = require('express-streamline');

Then, you can write any and all Express handlers in Streamline syntax by just replacing next with _.

// middleware handlers:
app.use(function (req, res, _) { ... });
app.param('user', function (req, res, _, user) { ... });

// route handlers:
app.get('/:user', function (req, res, _) { ... });
app.post('/:user', function (req, res, _) { ... });
// ... (all verbs supported)

// error handlers:
app.use(function (err, req, res, _) { ... });

By default, Streamlined middleware handlers will continue to the next middleware, while Streamlined route and error handlers won't. This is generally what you want, but you can specify whether next is called by explicitly returning true or false.

// middleware to blacklist banned IP addresses,
// but allow all other requests to pass through:
app.use(function (req, res, _) {
    var isBanned = db.bannedIPs.search(req.ips, _).length > 0;
    if (isBanned) {
        res.send(403);
        return false;   // end the response
    }
});

This module also supports Streamline's smart global context. If present, the context is reset for every request, so data can safely be added to it without affecting other requests.

var globals = require('streamline/lib/globals');

// middleware to set a global `locale` variable on every request,
// for lower-level modules to use:
app.use(function (req, res, __) {
    // parse locale... then:
    globals.context.locale = locale;
});

If you run into any issues, file a bug!

Changelog

See CHANGELOG.md.

License

MIT. © 2012-2015 Aseem Kishore.

Credits

TJ Holowaychuk for the awesome Express, and Bruno Jouhier for the awesome Streamline.

Seth Yuan's streamline-express for the inspiration and motivation. streamline-express has supported Express 3 for longer than this module, and it currently also supports more advanced Express 3 features (like passing multiple Streamlined handlers to the same app.verb call). I believe this module has a cleaner API and more robust implementation, however, but I'm biased. =) Both modules get the job done just fine!