# smart-session

> Node.js session handling middleware

Latest version **0.0.6** (published 2015-06-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install smart-session
pnpm add smart-session
yarn add smart-session
bun add smart-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.0.6 |
| Published | 2015-06-29 |
| First published | 2015-01-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.8 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Dron Rathore |
| Maintainers | dronrathore |
| Keywords | express-session, session, node-session, smart-session |

## Links

- npm: https://www.npmjs.com/package/smart-session
- Repository: git@github.com:dronrathore/smart-session
- Homepage: https://github.com/dronrathore/smart-session
- Issues: https://github.com/dronrathore/smart-session/issues
- npm.io page: https://npm.io/package/smart-session

## Dependencies (2)

- [redis](https://npm.io/package/redis.md) *
- [cookies](https://npm.io/package/cookies.md) *

## 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.0.6 (latest) — 2015-06-29
- 0.0.5 — 2015-02-24
- 0.0.4 — 2015-01-22
- 0.0.3 — 2015-01-22
- 0.0.2 — 2015-01-22
- 0.0.1 — 2015-01-22

## README

smart-session
=============

[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/DronRathore/smart-session?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

An ExpressJS Middleware which manages your Session Hassle with a horizontal scaling factor.
Node-Redis uses queue to execute your query so I decided to create multiple clients to redis in case you are developing a Super high End Web Product.

##How to use

```javascript
var express = require("express")
var session = require("smart-session");
var app = express();
var config = {
    "redis":{
      "ip": "0.0.0.0",
    },
    "session":{
      "cookieName": "someCoolSessionCookieName" // doesn't matter if you don't give one
    }
}
app.use(session(config));
app.get("/winkCat/:catName", function(request, response){
    if (request.params.catName == "LittleWayne"){
      request.session.add("auth", {"name":"Wayne", wink: true});
      request.session.add("canWink", true);
    }
    if (request.session.canWink){
      response.json({
          "message" : "Oh My Love!"
      });
    } else {
      response.json({
        "message" : "You ain't shit!"
      });
    }
  request.session.update(); //donot forget to do this at the end of each request to achieve scaling! 
}
```
Well that was just an old fashioned way, isn't it? Lets be smart!
```javascript
var express = require("express")
var session = require("smart-session");
var app = express();
var config = {
    "redis":{
      "ip": "0.0.0.0",
    },
    "session":{
      "cookieName": "somethingWhichSoundsLikeMIAgentName" // if not then I have a default one
    }
}
app.use(session(config));
app.get("/winkCat/:catName", function(request, response){
    if (request.params.catName == "BruceWayne"){
      request.session.auth = {"name":"DirtyCat", wink: true};
      request.session.canWink =  true;
    }
    if (request.session.canWink){
      response.json({
          "message" : "Oh My Love!"
      });
    } else {
      response.json({
        "message" : "You ain't shit!"
      });
    }
}
// Add this as the last middleware and just stay cool!
app.use(function(req, res, next){
  request.session.update();
  next();
});
```
##Methods
####request.session.add(key, value)
Where Key can be any text value and Value, Well value can be anything, JSON object, buffer, I don't know whatever you wanna save.
####request.session.update()
Well, when you are done messing up with the session variable, just hit this function and it will save all your mess in a gentle way
###request.session.remove(key)
C'mon, the name reads the whole, remove a session variable
###request.session.destroy()
```
Satan = Initialise->Satan()
Satan->KillTheSession()
```
####Scaling
```javascript
var config = {
    "redis": {
        // Redis details
    },
    clientLimit: someIntegerValueThatDefinesYourScaling //Wooh! That's too long
}
```
##ToDos
 - Redis authentication(a bit lazy will do in few weeks)
 - More Fun!

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