# koa-state

> Koa state middleware

Latest version **1.1.0** (published 2016-05-01) · MIT license · 0 weekly downloads

## Install

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

## 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.1.0 |
| Published | 2016-05-01 |
| First published | 2016-04-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Julien Tilap LA VINH |
| Maintainers | tilap |
| Keywords | koa |

## Links

- npm: https://www.npmjs.com/package/koa-state
- Repository: https://github.com/tilap/koa-state
- Homepage: https://github.com/tilap/koa-state#readme
- Issues: https://github.com/tilap/koa-state/issues
- npm.io page: https://npm.io/package/koa-state

## Recent versions

- 1.1.0 (latest) — 2016-05-01
- 1.0.1 — 2016-04-25
- 1.0.0 — 2016-04-24

## README

Koa state [![NPM version][npm-image]][npm-url]
============================

Simple state layer middleware **for Koa 2**. As mentionned in official [koajs](http://koajs.com/):

> ctx.state
The recommended namespace for passing information through middleware and to your frontend views.

## Install

```
npm install --save koa-state
```

## Usage

```
const Koa = require('Koa');
const koaState = require('koa-state');

const app = new Koa();
app.use(koaState());

app.use(async (ctx, next) => {
  if (!ctx.hasState('my-key-state')) {
    ctx.setState('my-key-state', 'anything-as-value');
  }

  await next();
});

app.use(async (ctx, next) => {
  console.log(ctx.getState('my-key-state'));
  await next();
});

app.listen(3000);
```

## Options

You can customize the context key with ```app.use(koaState('contextKey'));```

## License

MIT



[npm-image]: https://img.shields.io/npm/v/koa-state.svg?style=flat
[npm-url]: https://npmjs.org/package/koa-state

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