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

express-session-unsigned

v1.0.0

Published

Setup session store with the given `options`.

Downloads

1

Readme

express-session

Setup session store with the given options.

Session data is not saved in the cookie itself, however cookies are used, so we must use the cookieParser() middleware before session().

Example

 app.use(connect.cookieParser())
 app.use(connect.session({ secret: 'keyboard cat', key: 'sid', cookie: { secure: true }}))

Options

  • key cookie name defaulting to connect.sid
  • store session store instance
  • secret session cookie is signed with this secret to prevent tampering
  • cookie session cookie settings, defaulting to { path: '/', httpOnly: true, maxAge: null }
  • proxy trust the reverse proxy when setting secure cookies (via "x-forwarded-proto")

Cookie options

By default cookie.maxAge is null, meaning no "expires" parameter is set so the cookie becomes a browser-session cookie. When the user closes the browser the cookie (and session) will be removed.

req.session

To store or access session data, simply use the request property req.session, which is (generally) serialized as JSON by the store, so nested objects are typically fine. For example below is a user-specific view counter:

app.use(cookieParser())
app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }}))

app.use(function(req, res, next){
  var sess = req.session;
  if (sess.views) {
    res.setHeader('Content-Type', 'text/html');
    res.write('<p>views: ' + sess.views + '</p>');
    res.write('<p>expires in: ' + (sess.cookie.maxAge / 1000) + 's</p>');
    res.end();
    sess.views++;
  } else {
    sess.views = 1;
    res.end('welcome to the session demo. refresh!');
  }
})

Session#regenerate()

To regenerate the session simply invoke the method, once complete a new SID and Session instance will be initialized at req.session.

req.session.regenerate(function(err){
  // will have a new session here
});

Session#destroy()

Destroys the session, removing req.session, will be re-generated next request.

req.session.destroy(function(err){
  // cannot access session here
});

Session#reload()

Reloads the session data.

req.session.reload(function(err){
  // session updated
});

Session#save()

Save the session.

req.session.save(function(err){
  // session saved
});

Session#touch()

Updates the .maxAge property. Typically this is not necessary to call, as the session middleware does this for you.

Session#cookie

Each session has a unique cookie object accompany it. This allows you to alter the session cookie per visitor. For example we can set req.session.cookie.expires to false to enable the cookie to remain for only the duration of the user-agent.

Session#maxAge

Alternatively req.session.cookie.maxAge will return the time remaining in milliseconds, which we may also re-assign a new value to adjust the .expires property appropriately. The following are essentially equivalent

var hour = 3600000;
req.session.cookie.expires = new Date(Date.now() + hour);
req.session.cookie.maxAge = hour;

For example when maxAge is set to 60000 (one minute), and 30 seconds has elapsed it will return 30000 until the current request has completed, at which time req.session.touch() is called to reset req.session.maxAge to its original value.

req.session.cookie.maxAge;
// => 30000

Session Store Implementation

Every session store must implement the following methods

  • .get(sid, callback)
  • .set(sid, session, callback)
  • .destroy(sid, callback)

Recommended methods include, but are not limited to:

  • .length(callback)
  • .clear(callback)