# kth-node-session

> A Node.js module for setting up session middleware for Express.js apps.

Latest version **2.0.4** (published 2021-10-06) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install kth-node-session
pnpm add kth-node-session
yarn add kth-node-session
bun add kth-node-session
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.0.4 |
| Published | 2021-10-06 |
| First published | 2017-03-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 5.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | KTH |
| Maintainers | kthwebmaster, patricjansson, wkchung, exacs, ssundkvist, pmadjidi, kth-ci, emilstenberg |

## Links

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

## Dependencies (5)

- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [prettier](https://npm.io/package/prettier.md) ^2.4.1
- [pretty-quick](https://npm.io/package/pretty-quick.md) ^3.1.1
- [connect-redis](https://npm.io/package/connect-redis.md) ^3.4.2
- [express-session](https://npm.io/package/express-session.md) ^1.17.2

## Recent versions

- 2.0.4 (latest) — 2021-10-06
- 2.0.3 — 2021-08-18
- 2.0.2 — 2021-06-28
- 2.0.1 — 2021-06-24
- 2.0.0 — 2021-06-24
- 1.0.7 — 2021-06-23
- 1.0.6 — 2021-06-21
- 1.0.5 — 2021-05-11
- 1.0.4 — 2019-09-30
- 1.0.3 — 2017-03-21
- 1.0.2 — 2017-03-03

## README

# kth-node-session [![Build Status](https://travis-ci.org/KTH/kth-node-session.svg?branch=master)](https://travis-ci.org/KTH/kth-node-session)

A Node.js module for setting up session middleware for Express.js apps.

Enforces certain defaults that should improve security related to sessions.

Available session options: https://www.npmjs.com/package/express-session

Available Redis options: https://www.npmjs.com/package/connect-redis

# Usage

```javascript
const express = require('express')
const session = require('kth-node-session')

const app = express()

const options = {
  // set to true to enable session storage in RedisStore
  // default is to use MemoryStore
  useRedis: false,

  // this is used as redis prefix and session cookie name
  // must be set here or as individual settings for redis (prefix) and session (name)
  key: 'node-app.sid',

  // https://www.npmjs.com/package/connect-redis
  redisOptions: {
    // ...
  },

  // https://www.npmjs.com/package/express-session
  sessionOptions: {
    // secret must be set!
    secret: 'my-secret-string',

    // this should not be set when enabling Redis
    // or if using the default value
    store: null,
  },
}

app.use(session(options))
```

### Default cookie settings

The cookie has the following defult settings but each value can be overridden if needed:

```javascript
cookie: {
  secure: true,
  httpOnly: true,
  sameSite: 'Lax',
  path: '/'
},
```

The path attribute is preferably set to a more specific path so the cookie only is available where it´s needed.

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