Socket
Socket
Sign inDemoInstall

koa-flash

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    koa-flash

Flash messages for your koa application.


Version published
Weekly downloads
40
decreased by-61.17%
Maintainers
1
Install size
8.35 kB
Created
Weekly downloads
 

Readme

Source

#koa-flash

Flash messages for your koa application.

Build Status

Installation

$ npm install koa-flash

koa-flash also depends on koa-session. You must add koa-session as a middleware prior to adding koa-flash as seen in the example:

Example

var koa = require('koa')
  , session = require('koa-session')
  , flash = require('koa-flash');

var app = koa();

app.keys = ['foo'];
app.use(session());
app.use(flash());

app.use(function *() {
  if (this.method === 'POST') {
    this.flash = { error: 'This is a flash error message.' };
  } else if (this.method === 'GET') {
    this.body = this.flash.error || 'No flash data.';
  }
});

app.listen(3000);

Semantics

Flash data when set will be saved to the user's session for exactly one more request. You can save any javascript object into this.flash (Object, Number, String, etc.). A common use case is to save an error message from a POST request when redirecting to a GET request to display the form again.

Options

Flash data is saved into this.session['koa-flash'] by default. You can change this by passing in a key option.

app.use(flash({ key: 'foo' }));

Also, you can set defaultValue instead of {}.

app.use(flash({ defaultValue: 'bar' }));

License

MIT

Keywords

FAQs

Last updated on 01 Apr 2015

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc