@aex/session
TypeScript icon, indicating that this package has built-in type declarations

0.2.2 • Public • Published

Build StatusCoverage Status MIT license

@aex/session

Generic Node.js Session

This package is created for Aex, but it is useful for Node.js http callback.

Install

npm install @aex/session
# or
yarn add @aex/session

Usage

MemoryStore

import { MemoryStore, Cookie } from "@aex/session";
import * as http from "http";
const store = new MemoryStore();
const cookie = new Cookie(store);
const scope: any = {};
const server = http
  .createServer(function (req: any, res: any) {
    cookie.parse(req, res, scope).then(() => {
      scope.session.user = "alice";
      res.write("Hello World!");
      res.end();
    });
  })
  .listen(port);

RedisStore

RedisStore uses node-redis and takes exactly what createClient takes which described here;

import { RedisStore, Cookie } from "@aex/session";
import * as http from "http";
const store = new RedisStore();
const cookie = new Cookie(store);
const scope: any = {};
const server = http
  .createServer(function (req: any, res: any) {
    cookie.parse(req, res, scope).then(() => {
      scope.session.user = "alice";
      res.write("Hello World!");
      res.end();
    });
  })
  .listen(port);

scope is optional. If scope is not provided, session will be attached to req, make sure session is request specific even scope can be global.

/@aex/session/

    Package Sidebar

    Install

    npm i @aex/session

    Weekly Downloads

    8

    Version

    0.2.2

    License

    MIT

    Unpacked Size

    26.5 kB

    Total Files

    13

    Last publish

    Collaborators

    • calidion