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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@xof/lynx-session

v1.0.1

Published

Simple session middleware for Lynx

Downloads

2

Readme

@xof/lynx-session

npm version npm downloads GitHub

Fast, lightweight, and lynx-compatible session middleware for Lynx.

  • 🚀 High performance
  • 🍪 Cookie-based session IDs
  • 💾 Pluggable session stores
  • 🔒 Secure cookie support
  • ⚡ lynx-compatible API

Installation

npm install @xof/lynx-session

or

yarn add @xof/lynx-session

or

pnpm add @xof/lynx-session

Usage

const Lynx = require("@xof/lynx");
const session = require("@xof/lynx-session");

const app = new Lynx();

app.use(session({
    secret: "your-secret-key"
}));

app.get("/", (req, res) => {
    req.session.views = (req.session.views || 0) + 1;

    res.json({
        views: req.session.views
    });
});

app.listen(3000);

API

const session = require("@xof/lynx-session");

session(options)

Creates a session middleware.

app.use(session(options));

Session data is stored on the server. Only the session ID is stored inside the cookie.


Options

secret

Required

Secret used to sign session cookies.

app.use(session({
    secret: "my-super-secret"
}));

cookie

Configure session cookies.

Default:

{
    path: "/",
    httpOnly: true,
    secure: false,
    maxAge: null
}

Example:

app.use(session({
    secret: "secret",
    cookie: {
        maxAge: 86400000
    }
}));

cookie.maxAge

Cookie lifetime in milliseconds.

cookie: {
    maxAge: 1000 * 60 * 60
}

cookie.httpOnly

Prevent JavaScript from accessing cookies.

cookie: {
    httpOnly: true
}

cookie.secure

Only send cookies over HTTPS.

cookie: {
    secure: true
}

You can also use:

cookie: {
    secure: "auto"
}

cookie.sameSite

Controls cross-site cookie behavior.

Values:

  • false
  • true
  • "lax"
  • "strict"
  • "none"

Example:

cookie: {
    sameSite: "lax"
}

cookie.domain

Set cookie domain.

cookie: {
    domain: ".example.com"
}

cookie.path

Cookie path.

cookie: {
    path: "/"
}

cookie.priority

Cookie priority.

Values:

  • low
  • medium
  • high
cookie: {
    priority: "high"
}

cookie.partitioned

Enable Partitioned Cookies (CHIPS).

cookie: {
    partitioned: true
}

name

Session cookie name.

Default:

lynx.sid

Example:

session({
    name: "my.sid"
});

genid

Generate custom session IDs.

const crypto = require("node:crypto");

session({
    genid(req) {
        return crypto.randomUUID();
    },
    secret: "secret"
});

store

Custom session store.

session({
    secret: "secret",
    store: new MyStore()
});

proxy

Trust reverse proxies.

session({
    proxy: true
});

rolling

Always refresh cookie expiration.

session({
    rolling: true
});

resave

Force saving sessions.

session({
    resave: false
});

saveUninitialized

Save empty sessions.

session({
    saveUninitialized: false
});

unset

Behavior when deleting req.session.

Values:

  • keep
  • destroy
session({
    unset: "destroy"
});

req.session

Store data per visitor.

app.get("/", (req, res) => {
    req.session.user = {
        id: 1,
        username: "kyys"
    };

    res.json(req.session.user);
});

Session Methods

regenerate()

Generate a new session ID.

req.session.regenerate(err => {});

destroy()

Destroy current session.

req.session.destroy(err => {});

reload()

Reload session from store.

req.session.reload(err => {});

save()

Manually save session.

req.session.save(err => {});

touch()

Refresh expiration.

req.session.touch();

req.sessionID

Get current session ID.

console.log(req.sessionID);

req.session.cookie

Access current cookie.

console.log(req.session.cookie);

Session Store API

Every custom store should implement:

Required:

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

Recommended:

  • touch(sid, session, callback)

Optional:

  • all(callback)
  • clear(callback)
  • length(callback)

Example:

class MyStore {

    get(sid, callback) {}

    set(sid, session, callback) {}

    destroy(sid, callback) {}

}

Production

Do not use the default MemoryStore in production.

Instead, use a persistent store such as:

  • Redis
  • MongoDB
  • PostgreSQL
  • SQLite
  • MySQL

License

MIT


Links

  • GitHub: https://github.com/Xyraakyzzz/lynx-session
  • npm: https://www.npmjs.com/package/@xof/lynx-session