Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including koa-better-flash with all npm packages installed. Try it out:

var koaBetterFlash = require("koa-better-flash")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

koa-better-flash v0.0.4

Flash message middleware for Koa and Passport

koa-better-flash

build status code coverage code style styled with prettier made with lass license

Flash message middleware for Koa and Passport

Table of Contents

Install

npm:

npm install koa-better-flash

yarn:

yarn add koa-better-flash

Usage

const Koa = require('koa');
const Router = require('koa-router');
const session = require('koa-generic-session');
const flash = require('koa-better-flash');

const app = new Koa();
const router = new Router();

router.post('/', (ctx, next) => {
  // you can also pass an array of messages:
  // ctx.flash('info', [ 'hi', 'hello', 'good morning' ]);
  ctx.flash('info', 'hello world');
  ctx.status = 200;
});

router.get('/', ctx => {
  // to get all messages by type simply call `ctx.flash()`
  ctx.body = ctx.flash('info');
  // outputs: [ 'hello world ']
});

app.keys = [ 'keys' ];
app.use(session());
app.use(flash());
app.use(router.routes());
app.listen();

Contributors

NameWebsite
Nick Baughhttp://niftylettuce.com/

License

MIT © Nick Baugh

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free