jwa vs jose vs jsonwebtoken vs passport-jwt vs express-jwt
JWT Handling Libraries for Node.js Authentication
jwajosejsonwebtokenpassport-jwtexpress-jwtSimilar Packages:
JWT Handling Libraries for Node.js Authentication

express-jwt, jose, jsonwebtoken, jwa, and passport-jwt are npm packages used for handling JSON Web Tokens (JWTs) in Node.js applications. They provide utilities for signing, verifying, and managing JWT-based authentication, but differ significantly in scope, standards compliance, and integration patterns. jsonwebtoken is a general-purpose JWT library, jose offers modern, spec-compliant JWT/JWS/JWE support, jwa provides low-level cryptographic primitives, while express-jwt and passport-jwt are framework-specific middleware layers built on top of other JWT libraries for Express and Passport.js respectively.

Npm Package Weekly Downloads Trend
3 Years
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
jwa41,610,83810114.1 kB168 months agoMIT
jose31,252,4667,239258 kB0a month agoMIT
jsonwebtoken27,910,91818,13943.4 kB186a month agoMIT
passport-jwt2,089,9401,98452 kB43-MIT
express-jwt593,7554,51528.5 kB64a year agoMIT

JWT Handling in Node.js: express-jwt vs jose vs jsonwebtoken vs jwa vs passport-jwt

When building secure web applications with JSON Web Tokens (JWTs), choosing the right library is critical—not just for correctness, but for maintainability, standards compliance, and long-term security. The five packages under review—express-jwt, jose, jsonwebtoken, jwa, and passport-jwt—serve overlapping but distinct roles in the JWT ecosystem. Let’s unpack how they differ in practice.

🔑 Core Responsibilities: Token Creation vs Verification vs Middleware

Not all JWT libraries do the same thing. Some focus on signing/verifying tokens, others act as Express middleware, and one integrates tightly with Passport authentication.

jsonwebtoken: The Swiss Army Knife

This is the most widely used general-purpose JWT library. It handles both signing and verifying tokens using symmetric (HMAC) or asymmetric (RSA/ECDSA) algorithms.

// Signing a token
const jwt = require('jsonwebtoken');
const token = jwt.sign({ userId: 123 }, 'secret', { expiresIn: '1h' });

// Verifying a token
const payload = jwt.verify(token, 'secret');

It supports standard claims (exp, nbf, aud, etc.) and custom options like clock tolerance.

jose: Modern, Standards-Compliant, and Flexible

jose implements current IETF standards (RFC 7515–7519, RFC 8037) and supports JWS, JWE, JWT, and JWK. It works in both Node.js and browsers, and offers fine-grained control over cryptographic operations.

// Signing with jose (v4+)
import { SignJWT } from 'jose';

const secret = new TextEncoder().encode('secret');
const token = await new SignJWT({ userId: 123 })
  .setProtectedHeader({ alg: 'HS256' })
  .setIssuedAt()
  .setExpirationTime('1h')
  .sign(secret);

// Verifying
import { jwtVerify } from 'jose';
const { payload } = await jwtVerify(token, secret);

Unlike jsonwebtoken, jose requires explicit header declaration and uses modern WebCrypto-style APIs.

jwa: Low-Level Algorithm Wrapper

jwa is a minimal utility that only computes JWA (JSON Web Algorithms) signatures. It doesn’t handle JWT structure, claims validation, or expiration—it just signs and verifies raw payloads.

const jwa = require('jwa');
const hmac = jwa('HS256');

const signature = hmac.sign('header.payload', 'secret');
const isValid = hmac.verify('header.payload', signature, 'secret');

You’d typically use this only if you’re building your own JWT implementation from scratch—which you probably shouldn’t.

express-jwt: Express Middleware for Verification

This package is not a JWT signer. It’s an Express middleware that verifies incoming tokens and attaches the decoded payload to req.user.

const express = require('express');
const jwt = require('express-jwt');

const app = express();
app.use(jwt({ secret: 'secret', algorithms: ['HS256'] }));

app.get('/protected', (req, res) => {
  // req.user contains decoded token
  res.json({ user: req.user });
});

Note: As of 2023, express-jwt wraps jsonwebtoken internally for verification.

passport-jwt: Passport Strategy for JWT

This is a Passport.js strategy that extracts and verifies JWTs, integrating with Passport’s authentication flow.

const JwtStrategy = require('passport-jwt').Strategy;
const ExtractJwt = require('passport-jwt').ExtractJwt;

passport.use(new JwtStrategy({
  jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
  secretOrKey: 'secret'
}, (payload, done) => {
  // payload is decoded token
  User.findById(payload.userId, (err, user) => {
    if (err) return done(err, false);
    if (user) return done(null, user);
    else return done(null, false);
  });
}));

It delegates actual verification to jsonwebtoken.

⚙️ Cryptographic Flexibility and Standards Compliance

Algorithm Support

  • jsonwebtoken: Supports HS256/384/512, RS256/384/512, ES256/384/512, PS256/384/512. Uses Node.js crypto module.
  • jose: Full JWA support including EdDSA (Ed25519), and JWE encryption (which jsonwebtoken lacks entirely).
  • jwa: Only signing/verification primitives—no high-level JWT logic.
  • express-jwt / passport-jwt: Inherit algorithm support from jsonwebtoken.

Standards Adherence

  • jose strictly follows latest IETF specs and avoids legacy or non-standard extensions.
  • jsonwebtoken includes some non-standard features (e.g., jwt.decode(token, { complete: true }) returns header + payload + signature), which can be useful but may encourage anti-patterns.
  • jwa is standards-compliant at the algorithm level but doesn’t enforce JWT structure rules.

🛡️ Security Considerations

None Algorithm Vulnerability

Older JWT libraries were vulnerable to the "alg": "none" attack. All current versions of these packages reject none by default unless explicitly allowed.

  • jsonwebtoken: Throws error if none is used without { algorithms: ['none'] }.
  • jose: Requires explicit opt-in via { allowInsecureAlgorithm: true } in jwtVerify.
  • express-jwt: Forces you to specify algorithms array—preventing accidental none acceptance.
// express-jwt forces algorithm whitelist
app.use(jwt({ secret: 'secret', algorithms: ['HS256'] })); // ✅ safe

Secret Management

  • jose encourages use of Uint8Array secrets or KeyObject instances, aligning with modern crypto best practices.
  • jsonwebtoken accepts strings or buffers, which can lead to encoding issues if not handled carefully.

🧩 Integration Patterns

Building a Full Auth Flow

If you need to issue and verify tokens, you’ll likely combine tools:

  • Use jsonwebtoken or jose to sign tokens during login.
  • Use express-jwt or passport-jwt to protect routes.

Example with jsonwebtoken + express-jwt:

// Login route (issuing token)
app.post('/login', (req, res) => {
  const token = jwt.sign({ userId: user.id }, process.env.JWT_SECRET, { expiresIn: '1d' });
  res.json({ token });
});

// Protected route (verifying token)
app.use('/api', expressJwt({ secret: process.env.JWT_SECRET, algorithms: ['HS256'] }));

With jose, you’d write your own middleware since no official Express wrapper exists:

async function jwtMiddleware(req, res, next) {
  const auth = req.headers.authorization;
  if (!auth || !auth.startsWith('Bearer ')) return res.sendStatus(401);
  try {
    const token = auth.substring(7);
    const secret = new TextEncoder().encode(process.env.JWT_SECRET);
    const { payload } = await jwtVerify(token, secret);
    req.user = payload;
    next();
  } catch (err) {
    res.sendStatus(401);
  }
}

When to Avoid Certain Packages

  • Don’t use jwa alone for JWT handling—it’s too low-level and error-prone.
  • Avoid express-jwt if you’re not using Express—it’s framework-specific.
  • Don’t use passport-jwt unless you’re already using Passport.js—it adds unnecessary complexity otherwise.

📦 Maintenance and Future-Proofing

  • jose is actively maintained, supports modern JavaScript (ESM, TypeScript), and aligns with web platform standards. It’s the best choice for new projects requiring strong standards compliance.
  • jsonwebtoken remains stable and widely used, but development has slowed. Still safe for most use cases.
  • express-jwt and passport-jwt are wrapper libraries—their health depends on jsonwebtoken. Both are maintained but offer no advantage if you don’t need their specific integration.
  • jwa is stable but niche; unlikely to see major updates.

🆚 Summary Table

PackagePrimary RoleSigns Tokens?Verifies Tokens?Framework IntegrationStandards Compliance
jsonwebtokenGeneral-purpose JWT utilityNoneGood (with quirks)
joseModern, spec-compliant JWT/JWS/JWENoneExcellent
jwaLow-level JWA algorithm helper✅ (raw)✅ (raw)NoneAlgorithm-level only
express-jwtExpress middleware for JWT✅ (via jsonwebtoken)Express onlyInherits from jsonwebtoken
passport-jwtPassport strategy for JWT✅ (via jsonwebtoken)Passport.js onlyInherits from jsonwebtoken

💡 Final Guidance

  • For new greenfield projects: Start with jose—it’s future-proof, secure by default, and works everywhere.
  • For existing Express apps using simple HMAC tokens: jsonwebtoken + express-jwt is battle-tested and sufficient.
  • If you’re already using Passport.js: passport-jwt integrates cleanly.
  • Avoid jwa unless you’re implementing a custom JWT parser.

Remember: JWT libraries are security-critical dependencies. Always pin versions, audit regularly, and prefer libraries that enforce safe defaults over those that offer “convenience” at the cost of correctness.

How to Choose: jwa vs jose vs jsonwebtoken vs passport-jwt vs express-jwt
  • jwa:

    Choose jwa only if you're implementing a custom JWT parser or need direct access to JWA signing/verification primitives without higher-level abstractions. It handles cryptographic operations but doesn't manage JWT structure, claims validation, or expiration logic. For almost all real-world applications, higher-level libraries like jsonwebtoken or jose are safer and more productive choices.

  • jose:

    Choose jose for new projects where standards compliance, security, and future-proofing matter most. It fully implements current IETF JWT, JWS, and JWE specifications, supports modern cryptographic algorithms (including EdDSA), and works in both Node.js and browsers. Its API is more verbose but enforces safe practices. Ideal when you need encryption (JWE) or want to avoid legacy design choices found in older libraries.

  • jsonwebtoken:

    Choose jsonwebtoken if you need a battle-tested, straightforward library for signing and verifying basic JWTs with HMAC or RSA signatures. It’s widely adopted and integrates easily with many frameworks, but lacks support for JWE encryption and includes some non-standard features that can encourage anti-patterns. Still a solid choice for simple authentication flows in existing systems.

  • passport-jwt:

    Choose passport-jwt if your application already uses Passport.js for authentication and you want to add JWT support within Passport's strategy-based architecture. It handles token extraction and verification (via jsonwebtoken) and integrates with Passport's user serialization flow. Don't use it if you're not committed to Passport.js—it adds unnecessary complexity otherwise.

  • express-jwt:

    Choose express-jwt if you're building an Express application and need a simple, ready-made middleware to verify JWTs from incoming requests. It automatically decodes tokens and attaches payloads to req.user, but relies on jsonwebtoken under the hood—so you still need to manage secrets and algorithms carefully. Avoid it if you're not using Express or need advanced JWT features like encryption.