# jwt-tiny

> [![npm version](https://badge.fury.io/js/jwt-tiny.svg)](https://badge.fury.io/js/jwt-tiny) ![size](http://img.badgesize.io/digplan/jwt-tiny/master/module.mjs)

Latest version **1.0.6** (published 2025-05-03) · 0 weekly downloads

## Install

```sh
npm install jwt-tiny
pnpm add jwt-tiny
yarn add jwt-tiny
bun add jwt-tiny
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2025-05-03 |
| First published | 2022-01-20 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | cborkert |

## Links

- npm: https://www.npmjs.com/package/jwt-tiny
- npm.io page: https://npm.io/package/jwt-tiny

## Recent versions

- 1.0.6 (latest) — 2025-05-03
- 1.0.5 — 2022-09-05
- 1.0.4 — 2022-09-05
- 1.0.3 — 2022-02-01
- 1.0.2 — 2022-01-27
- 1.0.1 — 2022-01-27
- 1.0.0 — 2022-01-20

## README

# jwt-tiny

[![npm version](https://badge.fury.io/js/jwt-tiny.svg)](https://badge.fury.io/js/jwt-tiny)
![size](http://img.badgesize.io/digplan/jwt-tiny/master/module.mjs)

A lightweight, zero-dependency JWT (JSON Web Token) implementation for Node.js and modern browsers. Perfect for server-side authentication and data exchange.

## Features

- 🔒 Zero dependencies
- 📦 Ultra-lightweight (minimal bundle size)
- ⚡ Pure JavaScript implementation
- 🔄 Supports both Node.js and browser environments
- 🛡️ Secure token generation and verification
- 📝 Simple and intuitive API

## Installation

```bash
npm install jwt-tiny
```

## Usage

```js
import { JWT } from 'jwt-tiny'

// Initialize with your secret key
const secret = 'your-256-bit-secret'
const jwt = new JWT(secret)

// Create a payload with claims
const payload = {
  name: "John Doe",
  roles: ["admin"],
  iat: +new Date(), // issued at timestamp
  exp: +new Date() + (60 * 60 * 1000) // expires in 1 hour
}

// Create a JWT token
const token = jwt.create(payload)

// Verify and decode the token
const verifiedPayload = jwt.verifyJSON(token)
if (!verifiedPayload) {
  console.log('Invalid token')
} else if (verifiedPayload.exp < +new Date()) {
  console.log('Token has expired')
} else {
  console.log('Token is valid:', verifiedPayload)
}
```

## API Reference

### `new JWT(secret)`
Creates a new JWT instance with the provided secret key.

### `jwt.create(payload)`
Generates a new JWT token from the provided payload.

### `jwt.verify(token)`
Verifies and returns the decoded payload from a JWT token.

### `jwt.verifyJSON(token)`
Verifies and returns the decoded payload as a JSON object.

## Security Considerations

- Always use a strong, random secret key
- Keep your secret key secure and never expose it in client-side code
- Consider implementing token expiration (exp claim)
- Use HTTPS for token transmission

## License

MIT

---
_Source: https://npm.io/package/jwt-tiny · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
