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 🙏

© 2025 – Pkg Stats / Ryan Hefner

tin-cookie-jar

v1.0.0

Published

Yet another client side HTTP cookies CJS module for node.js

Downloads

5

Readme

workflow Jest coverage

tin-cookie-jar is a client side cookie library for data scraping and similar tasks.

Motivation

At the start of this project, the node.js ecosystem already contained several modules implementing client side collections of HTTP Cookies, informally named cookie jars. For instance:

  • tough-cookie: backed by Salesforce, this is a massively adopted, perfectly documented and (maybe even a bit overly) feature rich ESM;
  • cookiejar: a fairly popular CommonJS module doing the job, but barely described and not at all easy to learn by source code.

Having looked up for a tiny CJS cookie jar, fully covered by both documentation and tests, the author finally decided to make his own one.

Installation

npm install tin-cookie-jar

Usage

const os   = require ('node:os')
const Path = require ('node:path')

///// Accessing to the API

const {
  CookieJar, 
//  Cookie            // just in case you want to subclass it
} = require ('tin-cookie-jar')

///// Initializing

const cookieJar = new CookieJar ({
   path        : Path.join (os.tmpdir (), 'myBotCookies.txt'),
// ttl         : 1,   // minute(s)
// cookieClass : class extends Cookie {/*...*/}
})
// .on ('insert', name => {if (name === 'NID') console.log ('It spies on me!')})

///// Getting cookies (authentication routine outline)

if (!cookieJar.get ('SESSIONID')) { // may be restored from file
  const authResult = await fetch (authUrl, authOptions)
  cookieJar.setCookies (authResult.headers.getSetCookie ())
}

///// Using known cookies in subsequent requests

const dataUrl = URL ('http...')
const dataResult = await fetch (dataUrl, {
  headers: {
    cookie: this.cookieJar.getCookieHeader (dataUrl), // dataUrl is for filtering on domain/path/secure
    //...
  },
  //...
})

Description

The draft above almost completely describes the library's API. It's available via the CookieJar class. The internal Cookie class is exposed too, but solely for the case when you'll want to extend it and to use your own cookieClass.

CookieJar persists its content using the synchronous file API. Some TEMP directory is always at hand and the overhead of writing a dozen lines once a second is considered totally negligible, so there was no apparent reason to make a memory only version nor to use a pluggable storage.

The file is written automatically, as a side effect of setting/getting cookies. It's loaded automatically too, by the constructor, unless the TTL is expired — in which case the outdated file is deleted and the CookieJar is created empty. So a script using the library, if interrupted and restarted shortly after, will recall cookies received in the past session.

CookieJar checks for cookies' expiry times during both get and set operations, and updates the file when changes occur. To implement this logic, but avoid redundant operations, CookieJar is made observable: on each change, an event is emitted, the handler sets up a common internal flag, the file is wrote is the flag is set. The API user is free to add custom handlers for those events for logging etc.