npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mysession

v1.0.2

Published

HTTP web sessions handler

Downloads

7

Readme

MySession

Handler for multiple client sessions

How It Works

  1. Build a session container by calculated client key.
  2. Restore data previously stored.
  3. Auto-remove expired sessions.

Usage

JS Applications

Session control for webapps.

  1. Install by npm:

    $ npm install mysession

Config

MySession handle coocies, exiperd sessions, etc.

  1. session.open():

     const session = require("mysession"); //session handler
    
     // Settings
     session.open({
         cookieName: "SESSION", //name cookie
         maxage: 1000 * 60 * 60 //1h in miliseconds
     });
  2. session.init():

     const url = require("url"); //url parser
     const http = require("http"); //http server
     const session = require("mysession"); //session handler
    
     const server = http.createServer(function(req, res) {
         let parts = url.parse(req.url.toLowerCase(), true); //parse url
         let pathname = parts.pathname; //https://example.org/abc/xyz?123 = /abc/xyz
         //Static request => res.end()
         if (pathname.indexOf("/favicon.ico") > -1)
             return res.end(); //ignore icon request
    
         session.init(req, res);
         console.log(req.session);
         res.end(JSON.stringify(req.session), "application/json", () => {
             console.log(">", req.url, req.method, (Date.now() - req.session.mtime) + " ms");
         });
     });
  3. session.close():

     const url = require("url"); //url parser
     const http = require("http"); //http server
     const session = require("mysession"); //session handler
    
     //create server instance
     const server = http.createServer(function(req, res) {
         let parts = url.parse(req.url.toLowerCase(), true); //parse url
         let pathname = parts.pathname; //https://example.org/abc/xyz?123 = /abc/xyz
         //Static request => res.end()
         if (pathname.indexOf("/favicon.ico") > -1)
             return res.end(); //ignore icon request
    
         session.init(req, res);
         console.log(req.session);
         res.end(JSON.stringify(req.session), "application/json", () => {
             console.log(">", req.url, req.method, (Date.now() - req.session.mtime) + " ms");
         });
     });
    
     //capture Node.js Signals and Events
     function fnExit(signal) { //exit handler
         console.log("------------------");
         console.log("> Received [" + signal + "].");
         session.close();
         server.close();
         console.log("> Http server closed.");
         console.log("> " + (new Date()));
         process.exit(0);
     };
     server.on("close", fnExit); //close server event
     process.on("exit", function() { fnExit("exit"); }); //common exit signal
     process.on("SIGHUP", function() { fnExit("SIGHUP"); }); //generated on Windows when the console window is closed
     process.on("SIGINT", function() { fnExit("SIGINT"); }); //Press Ctrl-C / Ctrl-D keys to exit
     process.on("SIGTERM", function() { fnExit("SIGTERM"); }); //kill the server using command kill [PID_number] or killall node
     process.stdin.on("data", function(data) { (data == "exit\n") && fnExit("exit"); }); //console exit
    
     //start http and https server
     let port = process.env.port || 3000;
     server.listen(port, "localhost");
  4. Complete session example:

     const url = require("url"); //url parser
     const http = require("http"); //http server
     const session = require("mysession"); //session handler
    
     // Settings
     session.open({
         cookieName: "SESSION", //name cookie
         maxage: 1000 * 60 * 60 //1h in miliseconds
     });
    
     //create server instance
     const server = http.createServer(function(req, res) {
         let parts = url.parse(req.url.toLowerCase(), true); //parse url
         let pathname = parts.pathname; //https://example.org/abc/xyz?123 = /abc/xyz
         //Static request => res.end()
         if (pathname.indexOf("/favicon.ico") > -1)
             return res.end(); //ignore icon request
    
         session.init(req, res);
         console.log(req.session);
         res.end(JSON.stringify(req.session), "application/json", () => {
             console.log(">", req.url, req.method, (Date.now() - req.session.mtime) + " ms");
         });
     });
    
     //capture Node.js Signals and Events
     function fnExit(signal) { //exit handler
         console.log("------------------");
         console.log("> Received [" + signal + "].");
         session.close();
         server.close();
         console.log("> Http server closed.");
         console.log("> " + (new Date()));
         process.exit(0);
     };
     server.on("close", fnExit); //close server event
     process.on("exit", function() { fnExit("exit"); }); //common exit signal
     process.on("SIGHUP", function() { fnExit("SIGHUP"); }); //generated on Windows when the console window is closed
     process.on("SIGINT", function() { fnExit("SIGINT"); }); //Press Ctrl-C / Ctrl-D keys to exit
     process.on("SIGTERM", function() { fnExit("SIGTERM"); }); //kill the server using command kill [PID_number] or killall node
     process.stdin.on("data", function(data) { (data == "exit\n") && fnExit("exit"); }); //console exit
    
     //start http and https server
     let port = process.env.port || 3000;
     server.listen(port, "localhost");

test

npm test