# larvitsession

> Session handling module for node.js

Latest version **6.2.42** (published 2026-11-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install larvitsession
pnpm add larvitsession
yarn add larvitsession
bun add larvitsession
```

## Health

**Score 55/100 (C)** — status: active.

Positive: no vulnerabilities; recently updated; high maintenance score.

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

## Facts

| | |
|---|---|
| Version | 6.2.42 |
| Published | 2026-11-03 |
| First published | 2015-02-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Mikael 'Lilleman' Göransson |
| Maintainers | vktr, lilleman, gagge, klabbekluck, jaggu-snorr, dnidnl, jaggu-larvit-npm-publish |
| Keywords | session |

## Links

- npm: https://www.npmjs.com/package/larvitsession
- Repository: https://github.com/larvit/larvitsession
- Homepage: https://github.com/larvit/larvitsession#readme
- Issues: https://github.com/larvit/larvitsession/issues
- npm.io page: https://npm.io/package/larvitsession

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 6.2.42 (latest) — 2026-11-03
- 6.2.40 — 2026-10-05
- 6.2.39 — 2026-09-14
- 6.2.37 — 2026-08-31
- 6.2.36 — 2026-08-25
- 6.2.35 — 2026-08-17
- 6.2.33 — 2026-07-27
- 6.2.32 — 2026-07-13
- 6.2.31 — 2026-06-29
- 6.2.17 — 2025-12-08
- 6.2.16 — 2025-11-17
- 6.2.14 — 2025-10-20
- 6.2.13 — 2025-10-06
- 6.2.12 — 2025-09-22
- 6.2.11 — 2025-09-14
- … 140 more at https://npm.io/package/larvitsession/versions

## README

[![Build Status](https://github.com/larvit/larvitsession/actions/workflows/ci.yml/badge.svg)](https://github.com/larvit/larvitsession/actions)

# larvitsession

Session handling middleware

## Usage

The given example sets up larvitsession as a middleware to larvitbase. At the moment a database access is required via larvitdb.

```javascript
const Session = require('larvitsession');
const winston = require('winston');
const log = winston.createLogger({transports: [new winston.transports.Console()]});
const App = require('larvitbase');
const Db = require('larvitdb');

let session;
let conf;
let app;

const db = new Db({
	connectionLimit:   10,
	socketPath:        "/var/run/mysqld/mysqld.sock",
	user:              "foo",
	password:          "bar",
	charset:           "utf8mb4_general_ci",
	supportBigNumbers: true,
	database:          "dbname"
});

session = new Session({
	db:  db,
	log: log
});

// Create the app with a single middleware to view a page on port 8001
app = new App({
	httpOptions: 8001,
	middlewares: [function (req, res, cb) {
		if (req.session.data.counter === undefined) {
			res.session.data.counter = 1;
		} else {
			req.session.data.counter ++;
		}
		res.write('Your browsersession have viewed this page ' + req.session.data.counter + ' time(s)');
		cb();
	}]
});

// Add the session middlewares
// This way of adding the session middlewares works well on larvitbase-www as well, when there are many middlewares
app.middlewares.unshift(session.start);
app.middlewares.unshift(request('cookies').express());
app.middlewares.push(session.writeToDb);

app.run(function (err) {
	if (err) throw err;
});
```

# Changelog
## 6.0.0
- Upped lib versions
- Replaced callbacks with promises (not for the start/writeToDb middlewares)

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