Skip to content

Instantly share code, notes, and snippets.

@calidion
Last active February 6, 2021 06:27
Show Gist options
  • Save calidion/0e4acaa1f0bac02fbfa4ad0b339b277d to your computer and use it in GitHub Desktop.
Save calidion/0e4acaa1f0bac02fbfa4ad0b339b277d to your computer and use it in GitHub Desktop.
A general purpose async session for node.js

A general purpose async session for node.js

this package is created for project aex,

but it is general to all node.js http processing.

It is on it's early stage, any contribution is appriciated.

It provide abstract class Store and Session.

Currently only MemoryStore and CookieSession are available.

You can check the project at https://github.com/aex-ts-node/session.

Usage:

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment