# chestnut-session

> for chestnut-app

Latest version **0.2.6** (published 2021-09-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install chestnut-session
pnpm add chestnut-session
yarn add chestnut-session
bun add chestnut-session
```

## 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.6 |
| Published | 2021-09-26 |
| First published | 2017-08-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 14.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | nandy007 |
| Maintainers | nandy007 |

## Links

- npm: https://www.npmjs.com/package/chestnut-session
- Repository: https://github.com/nandy007/chestnut-session
- Homepage: https://github.com/nandy007/chestnut-session#readme
- Issues: https://github.com/nandy007/chestnut-session/issues
- npm.io page: https://npm.io/package/chestnut-session

## Dependencies (4)

- [ioredis](https://npm.io/package/ioredis.md) ^3.1.4
- [uid-safe](https://npm.io/package/uid-safe.md) ^2.1.4
- [chestnut-utils](https://npm.io/package/chestnut-utils.md) ^0.2.0
- [koa-session-minimal](https://npm.io/package/koa-session-minimal.md) ^3.0.4

## Recent versions

- 0.2.6 (latest) — 2021-09-26
- 0.2.5 — 2021-09-24
- 0.2.4 — 2018-04-18
- 0.2.3 — 2018-03-23
- 0.2.2 — 2018-03-19
- 0.2.1 — 2017-09-15
- 0.2.0 — 2017-08-12
- 0.1.2 — 2017-08-05
- 0.1.1 — 2017-08-05
- 0.1.0 — 2017-08-04
- 0.0.1 — 2017-08-03

## README

# chestnut-session Koa2会话处理

配合[chestnut-app](https://github.com/nandy007/chestnut-app)使用，也可单独在Koa2中使用

## 用法

app.js

```javascript

const Koa = require('koa');

const session = require('chestnut-session');

const app = new Koa();

// session配置
const config = {
	key: 'SESSIONID',// 配置会话id前缀
	storeConfig: {
    	id: 'main',
    	type: 'mysql',
    	database: 'test',
    	user: 'root',
    	password: 'root',
    	port: '3306',
    	host: 'localhost'
  	} // 必须，session存储配置，为数据库信息;
};

app.use(session(config));

```

## 静态方法

提供当session销毁的时候的回调处理，会传递会话id

```javascript

const session = require('chestnut-session');

// 有的时候会获取cookie信息来绑定一些逻辑并缓存起来，当需要在cookie不存在的时候销毁缓存可以添加处理函数
session.callback.add('custom key', function(sids){
	// 跟sids做一些销毁操作，sids为一个sid的数组，每个数组元素为都是会话id
});

```

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