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

sessids

v1.0.4

Published

amazing session system for express

Downloads

331

Readme

functions

main

require("sessids")(sessfile:string)

returns all functions below

sessions

require("sessids")().sessions

sessions is a express middleware that will allow you to use sessions. it sets req.session to a object that will look something like this: | name | description | |:------|------------:| | set(property, value) | sets a value on the session | | get(property) | gets a value from the session | | delete(property) | deletes a value from the session | | getAllProperties() | gets all properties with thier values and puts it into a object | | destroy() | destroys a session instantly | | id | id of the session | | lifetime | lifetime of the session(will not refresh) |

example

const express = require('express');
const app = express();

const sessids = require('sessids')();

app.use(sessids.sessions);

app.get('/get', (req, res) => {
    res.json(req.session.getAllProperties());
});

app.get('/set', (req, res) => {
    for (const key in req.query) {
        req.session.set(key, req.query[key]);
    }
    res.json(req.session.getAllProperties());
});

app.listen(3000, () => {
    console.log('Example app listening on port 3000!');
});

configue

require("sessids")().configue(scope: string, value: any);

configure sets scope in the configuration to value

scopes

| scope | default value | description | notes | |:-------------|:-------------:|------------:|:-----:| | lifetime | 86400 | the lifetime of all sessions created after setting this value || | sessfile |"sessions.json"| the file used for storing sessions, will automatically be changed when calling const sessids = require('sessids')("value");|do not change yourself|

session

(require("sessids")().session: class constructor(data?: object, lifetime?: number, id?: string) {}:{
    lifetime: number,
    storeddata: object,
    id: string,
    update: function() updates this session in the file,
    destory: function() destroys this session,
    data: {
        set: function(scope:string, value:any) updates value in this session,
        get: function(scope:string) gets value in this session,
        remove: function(scope:string) removes value in this session
    }
})

find

require("sessids")().find(search: {
    id?: string | undefined;
    data?: {
        value: any;
    } | undefined;
});
return:session[]

searches for the session meeting the requirements | name | usage | |:-----|------:| | id | search for a session with that session id | | data | a object any value in there will be required to also be the value in the object |

full examples

login screen example

  1. create a new directory

bash/ps

mkdir loginexample
  1. cd into the directory

bash/ps/cmd

cd loginexample
  1. initialize the directory

bash/ps/cmd

npm init -y
  1. install sessids and express

bash/ps/cmd

npm i sessids express 
  1. require sessids and express

index.js

const express = require('express');
const app = express();

const sessids = require('sessids')();
  1. initialize server

index.js

const express = require('express');
const app = express();

const sessids = require('sessids')();

app.use(sessids.sessions);

app.get('/', (req, res) => {
    res.json(req.session.getAllProperties());
});

app.get('/set', (req, res) => {
    for (const key in req.query) {
        req.session.set(key, req.query[key]);
    }
    res.json(req.session.getAllProperties());
});
  1. creating statics

index.js

const express = require('express');
const app = express();

const sessids = require('sessids')();

app.use(sessids.sessions);

app.get('/', (req, res) => {
    res.json(req.session.getAllProperties());
});

app.get('/set', (req, res) => {
    for (const key in req.query) {
        req.session.set(key, req.query[key]);
    }
    res.json(req.session.getAllProperties());
});

app.use(express.static("public"));
  1. create the public directory

bash/ps

mkdir public
cd public
  1. create a new file in public: login.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>example login page</title>
</head>
<body>
    <form action="submitlogin" method="post">
        <label for="username">username: </label><input name="username" id="username">
        <label for="password">password: </label><input name="password" id="password" type="password">
        <input type="submit">
    </form>
</body>
</html>
  1. setting up login callback

bash/ps/cmd

cd ../
npm i body-parser

index.js

const express = require('express');
const app = express();

const bodyParser = require('body-parser');

const sessids = require('sessids')();

app.use(bodyParser.urlencoded({ extended: true }));
app.use(sessids.sessions);

app.get('/', (req, res) => {
    res.json(req.session.getAllProperties());
});

app.get('/set', (req, res) => {
    for (const key in req.query) {
        req.session.set(key, req.query[key]);
    }
    res.json(req.session.getAllProperties());
});

app.post('/submitlogin', (req, res) => {
    req.session.set("username", req.body.username);
    req.session.set("password", req.body.password);
});

app.use(express.static("public"));

app.listen(3000, () => {
    console.log("example login system up and running!");
});
  1. try it out

bash/ps/cmd

node index.js

go to localhost:3000's login page

you will see a new file in root directory called sessions.json, after you have logged in, you will see it looks something like this:

{
    "sessions": [
        {
            "id": "w20nYhiPZ93fIyaUCbp7DETLquvjeMX!Q5l8ONKt46VAoGgBxkRsdFrJzHScW1mGMuWovgsfdymZ78Y3Tjea1EU2xC6SpKhcA0IVlqJHNP594k!rnFbQDwBiXLzOtR",
            "data": {
                "username": "test",
                "password": "test"
            },
            "lifetime": 86300
        }
    ]
}
  1. improve user experience

index.js

const express = require('express');
const app = express();

const bodyParser = require('body-parser');

const sessids = require('sessids')();

app.use(bodyParser.urlencoded({ extended: true }));
app.use(sessids.sessions);

app.get('/', (req, res) => {
    res.json(req.session.getAllProperties());
});

app.get('/set', (req, res) => {
    for (const key in req.query) {
        req.session.set(key, req.query[key]);
    }
    res.json(req.session.getAllProperties());
});

app.post('/submitlogin', (req, res) => {
    req.session.set("username", req.body.username);
    req.session.set("password", req.body.password);
    res.redirect('/');
});

app.get('/submitlogin', (req, res) => {
    res.redirect('/');
});

app.use(express.static("public"));

app.listen(3000, () => {
    console.log("example login system up and running!");
});