Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 4 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

jsonwebtoken

Create, verify and decode JSON Web Tokens for authentication and secure data transmission.

Auth and security librariesNPM

GitHubWebsite

1. License

License from npm.

github.com/auth0/node-jsonwebtoken

From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error

What jsonwebtoken does

jsonwebtoken is the plain sign/verify/decode JWT library for Node.js, and since version 9 it refuses unsigned tokens, short RSA keys and mismatched key types unless you opt back in by name.

jsonwebtoken popularity

79 / 100
Gid Score, #122 overall
84.5M
downloads a week, npm
18.2K
GitHub stars
149
agent projects use it
jsonwebtoken: downloads per weeknpm, jsonwebtoken 84,480,307
jsonwebtoken: GitHub starsauth0/node-jsonwebtoken 18,184

Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated

How jsonwebtoken is used

  • jsonwebtoken is a dependency in 149 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (3.1% of the 4,867 JavaScript/TypeScript ones), #3 of 141 in auth and security libraries.
  • Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 452; those are left out of every share on this page.
  • The most used alternative in our scan is jose (108 projects).
  • Projects that use it most often also use dotenv (70.5%), Express (60.4%), cors (53.7%).
  • It is more common in projects set up for Devin Desktop (9.3%) than for OpenAI Codex (1.5%).

By coding agent

84 projects, 3.4%
78 projects, 2.4%
61 projects, 2.0%
26 projects, 9.3%
10 projects, 7.1%
8 projects, 1.7%
7 projects, 1.5%
7 projects, 6.3%

Often used with

In 70.5% of its projects
In 60.4% of its projects
In 53.7% of its projects
In 39.6% of its projects
In 59.7% of its projects
In 35.6% of its projects
In 34.2% of its projects
In 31.5% of its projects

jsonwebtoken in practice

Strengths

Unsigned tokens and weak RSA keys are refused by default

In v9, <code>verify()</code> rejects unsigned tokens unless you list <code>none</code> in <code>options.algorithms</code>. Signing rejects RSA keys under 2048 bits unless you set <code>allowInsecureKeySizes</code>.

Claim checks live in one verify call

<code>verify</code> takes expected values for audience, issuer, JWT ID, subject and nonce, plus <code>maxAge</code> and <code>clockTolerance</code>. The audience can be matched against strings or regular expressions.

Errors you can branch on

Failures come back as <code>TokenExpiredError</code>, <code>NotBeforeError</code> or <code>JsonWebTokenError</code>. Each has a fixed message such as <code>'jwt expired'</code> or <code>'jwt malformed'</code>.

Keys can be fetched per token

In callback mode, the key argument can be a function that looks up the key from the token header. The README shows this with <code>jwks-rsa</code> and the header's <code>kid</code>.

Watch out for

decode() checks nothing

<code>jwt.decode</code> reads the payload without validating the signature. The README warns against using it for untrusted messages and points to <code>jwt.verify</code> instead.

A verified payload is still user input

Even after verification, the README says a payload from an untrusted source must be sanitized, and you should only read the properties you expect.

String durations without units mean milliseconds

<code>expiresIn</code>, <code>notBefore</code> and <code>maxAge</code> treat numbers as seconds. A unitless string is read as milliseconds, so <code>"120"</code> means <code>"120ms"</code>.

Sign a token, then verify it (synchronous)

var jwt = require('jsonwebtoken');
var token = jwt.sign({ foo: 'bar' }, 'shhhhh');

// verify a token symmetric - synchronous
var decoded = jwt.verify(token, 'shhhhh');
console.log(decoded.foo) // bar

// invalid token - synchronous
try {
  var decoded = jwt.verify(token, 'wrong-secret');
} catch(err) {
  // err
}

More about jsonwebtoken

Head to head
Packages around it
  • dotenv: env variables
  • express: web framework
  • cors: CORS middleware
  • bcryptjs: password hashing
  • zod: schema validation
  • axios: HTTP client
More in Auth and security libraries

Alternatives

jsonwebtoken This page

MITGid 7984.5M/wk

jose

Comprehensive JWT and JWK handling for Node.js and web runtimes.

MITGid 75244M/wk

Passport.js

Modular authentication middleware for Node.js supporting OAuth, JWT and local strategies.

MITGid 6910.5M/wk

Compare jsonwebtoken with another tool

Get started

Install it.

npm install jsonwebtoken

Rules for your agent

Paste into AGENTS.md or CLAUDE.md
## jsonwebtoken
- Use `jwt.verify` for any token from a client or external request. Never use `jwt.decode`, which does not check the signature.
- Pass `algorithms` explicitly to `verify` (for example `['RS256']`). Do not add `'none'` unless unsigned tokens are really intended.
- Treat the decoded payload as user input. Read only the properties you expect.
- Give `expiresIn`, `notBefore` and `maxAge` a number of seconds or a string with units (`'1h'`, `'7d'`). A unitless string like `'120'` means milliseconds.
- Put a claim either in the payload (`exp`, `nbf`, `aud`, `sub`, `iss`) or in the options, never both. Use an object literal payload so claims get set.
- Use RSA keys of at least 2048 bits, and never sign HS* tokens with an asymmetric key. Do not set `allowInsecureKeySizes` or `allowInvalidAsymmetricKeyTypes` in new code.
- Handle `TokenExpiredError`, `NotBeforeError` and `JsonWebTokenError` separately when mapping failures to responses.