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

session-mg

v1.0.4

Published

A SJDB based session manager with object storage, time expiration and events API

Downloads

14

Readme

session-mg icon NPM #Documentation ##Description session-mg is a simple session/credentials manager that helps you to store key/value in a JSON database (based on SJDB), who can expire with time, session-mg also provide an events API. I use it to temporaly store user info that i took from my SJDB database, reducing heavy file manipulation, that mean reducing CPU usage and so make my apps faster, moreover basic sessions usage ! It could be same for you ;)

##SessionManager public class Three There is one class, SessionManager, who take as argument, the session-mg folder path (where sessions and logs will be stored).

expiration
    .active( true || false@default ): En/Disable sessions expiration
    .time( int >= 1 && < 2147483647 || 1800000@default ): Set default time before session expiration
events
	.fire( eventName ): Fire event
add( sessionKey, value ): Add a new session
get( sessionKey ): Get a session by session key
append( sessionKey, key, value ): Append a key/value to a session by his sessionKey
update( sessionKey, newValue ): Update the value of a session
delete( sessionKey ): Delete a session by his session key
CLI( identifier ): Start SJDB Query CLI

##Events

added -> Fired each time that a session is created.
getted -> Fired each time that a session is getted.
appended -> Fired each time that a sessions is appended.
updated -> Fired each time that a session is updated.
deleted -> Fired each time that a session is deleted.
expired -> Fired each time that a session expired.

#Tutorials ##Instantiating session-mg Like there is just one class, no need to make two vars, one for require and the other for new class, at least that you want two session managers.

const sessions = new ( require('session-mg') ).SessionManager('./session')

##Adding and getting session Know that we instantiated session-mg, let's add sessions !

(...)
sessions.add('mySess', { name: 'Alexandre', pass: 'mg' })
console.log( 'My session:', sessions.get('mySess') )

If sessions doesn't exist, will return undefined. That simple right ? :)

##Make session expire By default every sessions expire after 1 800 000 ms (30 mins), but you can specify expiration time as 3th argument

(...)
sessions.add('shortSess', 'Can be string too!', 12000)
// Will expire in 12 000ms

##Updating, appending and deleting session Moreover adding and getting, you can do simple operations on sessions.

(...)
session.create('changingSess', 010101) // Can be int
sessions.update('changingSess', { now: `I'm object!`, later: 'A bigger object! ;o' })
sessions.append('changingSess', 'ImNewKey', { desc: 'And new object!' })
sessions.delete('changingSess') // No more session ! :(

##Setting and handling events To help you build awesomes projects, you can use the session-mg events API !

First, like Documentation -> Events says it, there is actualy 6 events that you can handle

(...)
sessions.on('added', () => { console.log('A new session !') })
sessions.add('sess', 12)
// output: 'A new session !'
// And you can do the same thing with the 5 other events

Well it's great but.. that kind of pretty limited.. But of course, with session-mg we can do more complex handlings !

(...)
session.on('added', (addedSess) => { console.log('Session named', deletedSess.name, 'was added!' } )
// events API return targeted session

session.add('sess', { name: 'Joe', pass: 0000 } )

// output: 'Session named Joe was added!'

Pretty easy no ? ;)

##Expiration settings Well, there is only 2 settings, active and time, that can be reached by sessions.expiration., where active define if sessions expire, can be false or true (by default), and time set time before session expiration if actived (by default 1 800 000 ms).

#Credits ##Made by Alexandre Daubricourt, Paris, France.

mail: [email protected] Twitter: @AlexDaubricourt Github: Akronae npm: akrone ##Icon

##LICENSE GPL-3.O