# cookie-flash-messages

> Use cookies to inject flash messages into your express.js pages

Latest version **0.2.1** (published 2016-12-20) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install cookie-flash-messages
pnpm add cookie-flash-messages
yarn add cookie-flash-messages
bun add cookie-flash-messages
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2016-12-20 |
| First published | 2015-11-11 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Maxime GHIGNET |
| Maintainers | mghignet |
| Keywords | cookie, express, flash, messages |

## Links

- npm: https://www.npmjs.com/package/cookie-flash-messages
- Repository: https://github.com/mghignet/cookie-flash-messages
- Homepage: https://github.com/mghignet/cookie-flash-messages#readme
- Issues: https://github.com/mghignet/cookie-flash-messages/issues
- npm.io page: https://npm.io/package/cookie-flash-messages

## Dependencies (2)

- [cookie](https://npm.io/package/cookie.md) 0.2.3
- [escape-html](https://npm.io/package/escape-html.md) 1.0.3

## Recent versions

- 0.2.1 (latest) — 2016-12-20
- 0.2.0 — 2016-12-19
- 0.1.1 — 2015-11-11
- 0.0.1 — 2015-11-11

## README

# Cookie-flash-messages
Use cookies to inject flash messages into your Express.js pages.
Useful when you want to display a confirmation/error message when submitting a form. You usually process the form and, depending of the result, redirect the user and display a message.

You can use sessions to do so but the aim was to avoid storing data on the server side.

## How to use

### Install
This is a middleware to be used in Express.js.

`npm install cookie-flash-messages`

### Require and declare
In your Express.js app:
```javascript
var express = require('express');
var app = express();
var cookieFlashMessages = require('cookie-flash-messages');

...

// Declare the middleware before your routes
app.use(cookieFlashMessages);
```

### Use

You will then be allowed to call a new method `res.flash()` in your routes:
```javascript
res.flash('your-message-type', 'Your message')
res.redirect('/your-page');
```
The type can be anything. I personnally use `error|info|success|warning`.

## Display

If a flash message was set, it will be available as a `flashMessage` variable in your templates. The objects looks like this:
```javascript
{
    type: 'your-message-type',
    text: 'Your message'
}
```

For example in a Jade template, a simple example looks like this:
```jade
if flashMessage
    div(class='flash-message ' + flashMessage.type)= flashMessage.text
```

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