New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

express-streamline

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-streamline

Express monkey-patch to support Streamline syntax.

  • 0.5.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13
increased by30%
Maintainers
1
Weekly downloads
 
Created
Source

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!

Keywords

FAQs

Package last updated on 20 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc