# varsession

> A simple way to manage Session Variables with node.js

Latest version **0.2.1** (published 2015-10-14) · GNU GPL v2 license · 0 weekly downloads

## Install

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

## 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 | 2015-10-14 |
| First published | 2015-02-27 |
| Weekly downloads | 0 |
| License | GNU GPL v2 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Samir ROUABHI |
| Maintainers | rouabhi |
| Keywords | Session, Variables |

## Links

- npm: https://www.npmjs.com/package/varsession
- Repository: https://rouabhi@bitbucket.org/cloudestin/varsession
- Homepage: https://bitbucket.org/cloudestin/varsession#readme
- npm.io page: https://npm.io/package/varsession

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@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

## Recent versions

- 0.2.1 (latest) — 2015-10-14
- 0.2.0 — 2015-10-14
- 0.1.0 — 2015-09-05
- 0.0.4 — 2015-02-27

## README

# varsession #

**varsession** offers a very simple way to manage *Session Variables* with node.js when using ```express.js```

## How does it work? ##
First, you have to activate session management using  _express-session_ middleware. 
```javascript
var express = require('express');
var app = express();
var session = require('express-session');

app.use( session({secret:'mySecretKey', cookie: { maxAge: 600000 }, resave:false, saveUninitialized:true});
```

With this lines, sessions are now managed. This means that you have a separate environment for each connection opened in the server. In this environment, you can now create session variables to store data throughout requests to the server.

## How? ##
**varsession** offers simple functions to define session variables:

```javascript
var varSession = require('varsession');

function setVariables(req,res){
    var varsession = varSession(req);

    // we define here session variables named "name" and "surname"
    varsession("name","ROUABHI");
    varsession("surname","Samir");
    res.status(200).send("Variables defined.").end();
}

function getVariables(req,res){
    var varsession = varSession(req);

    // we use now session variables
    res.status(200).send("My name is :"+ varsession("surname") + " " + varsession("name")).end();
}

app.get("/set" , setVariables);
app.get("/get" , getVariables);
```

Beware : the session variables are stored in cookies so they are registred only when there is a HTTP response.

## Different possibilities ##
 - ```varsession()``` returns all the variables of the session
 - ```varsession('variable')``` gets the value of a variable
 - ```varsession('variable',{value})``` sets a value in a variable
 - ```varsession('variable',null)``` deletes a variable
 - ```varsession('variable','field')``` gets a value in a field of a variable. is similar to ```varsession('variable')['field']```
 - ```varsession('variable','field',{value})``` sets a value in a field of a variable.

Old functions of v0.1 ```.set```, ```.get```, ```.clear``` and ```.setAttr``` are now deprecated.

## Other fonctions ##
2 other fonctions currently available:
```javascript
var varsession = varSession(req);

// destroys the session and all session variables defined
varsession.abandon();

// returns the ip address of the device that made the request.
console.log( varsession.ip() );
```

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