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

express-middleware-jwt

v1.0.0

Published

jwt authentication middleware for ExpressJS

Readme

express-mjwt

This module provides ExpressJs middleware to validate JWT via the jsonwebtoken module.

Install

$ npm install express-mjwt

API

authJwt(options)

Options has the following parameters:

  • secret: jwt.Secret (required): The secret as a string to retrieve the secret.
  • algorithms (required): Specifies the algorithms to be used for token verification.
  • invalidAuthenticationHeaderMessage (optional): A string defining the error message displayed when the authentication header is invalid.
  • noAuthenticationHeaderMessage (optional): A string defining the error message displayed when no authentication header is provided.
  • tokenExpireMessage (optional): A string defining the error message displayed when the token has expired.
  • tokenFailureVerificationMessage (optional): A string defining the error message displayed when token verification fails.

Usage

Basic usage using an HS256 secret:

import { authJwt } from 'express-mjwt';

app.get(
  '/protected',
  authJwt({ secret: 'jwt_secret', algorithms: ['HS256'] }),
  (req, res) => {
    if (!req.auth.admin) return res.sendStatus(401);
    res.sendStatus(200);
  }
);

The decoded JWT payload is available on the request via the auth property.

Required Parameters

The algorithms parameter is required to prevent potential downgrade attacks when providing third party libraries as secrets.

:warning: Do not mix symmetric and asymmetric (ie HS256/RS256) algorithms: Mixing algorithms without further validation can potentially result in downgrade vulnerabilities.

authJwt({
  secret: 'jwt_secret',
  algorithms: ['HS256'],
  //algorithms: ['RS256']
});

Typescript

A JWTRequest type is provided from express-mjwt, which extends express.Request with the auth property. I

import { Response } from 'express';
import { authJwt, JWTRequest } from 'express-mjwt';

app.get(
  "/protected",
  authJwt({ secret: 'jwt_secret', algorithms: ['HS256'] }),
  function (req: JWTRequest, res: Response) {
    if (!req.auth?.admin) return res.sendStatus(401);
    res.sendStatus(200);
  }
);

License

This project is licensed under the MIT license. See the LICENSE file for more info.