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

jwt-manager

v2.2.1

Published

A JS Library for managing JWT Tokens

Readme

JWT Manager

Build Status npm version npm

JWT Manager is a Javascript Library designed to make storing and retrieving JWT tokens easier. It has an easy to use API designed to make working with JSON Web Tokens much easier. It is written using Typescript and has no dependencies.

Installation

You can install this package by running npm install --save jwt-manager.

You can then import the library using the following:

import JWTManager from 'jwt-manager';
window.JWTManager = new JWTManager();

Usage

Using the JWT Manager library you can set, get, forget and refresh JWT Tokens. By default they are stored as a cookie, however you can change this to local storage if you would prefer. To change the store to local storage, simply use the following:

window.JWTManager.useLocalStore();

Setting JWT Tokens

Once you retrieve a valid JWT Token from your server, you can store the JWT token by using the following method call: JWTManager.setToken('jwt-token'). This will then store the JWT Token in the storage driver chosen (defaults to cookie).

Getting JWT Tokens

Once you have set a JWT Token, you can easily retrieve it at any time by using the following method call JWTManager.getToken(). This will then return the JWT Token.

Forgetting JWT Tokens

If you would like to remove the stored JWT Token, you can simply call the forget method as follows: JWTManager.forget().

Refreshing JWT Tokens

To refresh a JWT Token, you simply need to call the refresh method: JWTManager.refresh('new-jwt-token').

Decoding Tokens

If you would like to decode the JWT token, you can simply use the decode method: JWTManager.decode(). This will check to see if there is a token set and if there is, it will decode it and return the decoded object.

Monitoring Tokens

When dealing with JWT Tokens it is useful to monitor when the token is close to expiring so a request can be made to generate a new token. JWT manager handles this using a useful monitor method. For example:

window.JWTManager.monitor((token) => {
    // Make request to refresh token here
    // Then call the JWTManager.refresh() method and pass in your new token
});

This will then check on an interval basis to see if the JWT Token is going to expire within the next 60 seconds. If it is, it will run the callback. You can also pass a second parameter to the monitor function. This will set the number of seconds until the token expires, before it triggers the callback. By default it is set to 60. In the below example, it will trigger the callback when the token is due to expire within the next 30 seconds.

window.JWTManager.monitor((token) => {
    // Make request to refresh token here
    // Then call the JWTManager.refresh() method and pass in your new token
}, 30);

JWT Manager will automatically check in ten second intervals.

Test Suite

You can run the test suite by running npm run test