# koa-flash

> Flash messages for your koa application.

Latest version **1.0.0** (published 2015-04-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-flash
pnpm add koa-flash
yarn add koa-flash
bun add koa-flash
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2015-04-01 |
| First published | 2014-03-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 39 |
| Author | Rick Harrison |
| Maintainers | rickharrison |
| Keywords | koa, middleware, flash, messages, session |

## Links

- npm: https://www.npmjs.com/package/koa-flash
- Repository: https://github.com/rickharrison/koa-flash
- Issues: https://github.com/rickharrison/koa-flash/issues
- npm.io page: https://npm.io/package/koa-flash

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2015-04-01
- 0.1.1 — 2015-04-01
- 0.1.0 — 2014-12-26
- 0.0.3 — 2014-04-20
- 0.0.2 — 2014-03-20
- 0.0.1 — 2014-03-20

## README

#koa-flash

Flash messages for your [koa](https://github.com/koajs/koa) application.

[![Build Status](https://travis-ci.org/rickharrison/koa-flash.svg?branch=master)](https://travis-ci.org/rickharrison/koa-flash)

## Installation

```js
$ npm install koa-flash
```

koa-flash also depends on [koa-session](https://github.com/koajs/session). You must add koa-session as a middleware prior to adding koa-flash as seen in the example:

## Example

```js
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.

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

Also, you can set `defaultValue` instead of `{}`.

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

## License

MIT

---
_Source: https://npm.io/package/koa-flash · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
