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

apikeyscreator

v1.0.0

Published

Real API Keys Creator System with JWT Authentication

Readme

API Keys Creator System

A production-ready API key management system built with Hono, Node.js, and JSON file storage.

Features

  • User Authentication: Register and login with email/password using JWT
  • API Key Management: Create, read, update, and delete API keys
  • Real Authentication: BCrypt password hashing and JWT token verification
  • Usage Tracking: Track when API keys are used
  • Key Status Management: Enable/disable API keys
  • JSON File Storage: Persistent storage in JSON files

Installation

npm install

Running the Server

Development mode (with auto-reload):

npm run dev

Production mode:

npm start

The server runs on http://localhost:3000 by default.

Environment Variables

PORT=3000
JWT_SECRET=your-secret-key-change-in-production

API Endpoints

Authentication (Public)

Register

POST /auth/register
Content-Type: application/json

{
  "email": "[email protected]",
  "password": "securepassword"
}

Response:

{
  "message": "User registered successfully",
  "user": { "id": "...", "email": "[email protected]" },
  "token": "eyJhbGc..."
}

Login

POST /auth/login
Content-Type: application/json

{
  "email": "[email protected]",
  "password": "securepassword"
}

Response:

{
  "message": "Login successful",
  "user": { "id": "...", "email": "[email protected]" },
  "token": "eyJhbGc..."
}

API Keys (Protected - Requires Authorization Header)

All requests to /api/keys/* require an Authorization: Bearer <token> header.

List API Keys

GET /api/keys
Authorization: Bearer eyJhbGc...

Response:

{
  "message": "API keys retrieved successfully",
  "count": 2,
  "keys": [
    {
      "id": "1234567890",
      "name": "Production Key",
      "key": "sk_a1b2c3...d4e5f6",
      "fullKey": "sk_a1b2c3d4e5f6...",
      "active": true,
      "createdAt": "2024-01-01T10:00:00.000Z",
      "lastUsed": null
    }
  ]
}

Create API Key

POST /api/keys
Authorization: Bearer eyJhbGc...
Content-Type: application/json

{
  "name": "My New Key"
}

Response:

{
  "message": "API key created successfully",
  "key": {
    "id": "1234567890",
    "name": "My New Key",
    "key": "sk_abcd1234efgh5678ijkl9012mnop3456",
    "active": true,
    "createdAt": "2024-01-01T10:00:00.000Z"
  }
}

Get Single API Key

GET /api/keys/:id
Authorization: Bearer eyJhbGc...

Update API Key

PUT /api/keys/:id
Authorization: Bearer eyJhbGc...
Content-Type: application/json

{
  "name": "Updated Name",
  "active": false
}

Delete API Key

DELETE /api/keys/:id
Authorization: Bearer eyJhbGc...

Record Key Usage

POST /api/keys/:id/usage
Authorization: Bearer eyJhbGc...

File Structure

apikeyscreator/
├── src/
│   ├── server.js              # Main Hono app
│   ├── middleware/
│   │   └── auth.js            # JWT authentication middleware
│   ├── routes/
│   │   ├── auth.js            # Authentication endpoints
│   │   └── apiKeys.js         # API key management endpoints
│   └── utils/
│       ├── db.js              # JSON file database
│       └── jwt.js             # JWT token generation/verification
├── data/
│   ├── users.json             # User storage
│   └── keys.json              # API keys storage
├── package.json
└── README.md

Security Notes

⚠️ Before production:

  1. Change the JWT_SECRET environment variable
  2. Use HTTPS/TLS
  3. Implement rate limiting
  4. Consider migrating to a real database (PostgreSQL, MongoDB)
  5. Add input validation and sanitization
  6. Implement refresh tokens
  7. Add audit logging
  8. Store sensitive keys securely

Example Usage with cURL

# Register
curl -X POST http://localhost:3000/auth/register \
  -H "Content-Type: application/json" \
  -d '{"email":"[email protected]","password":"pass123"}'

# Login
curl -X POST http://localhost:3000/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"[email protected]","password":"pass123"}'

# Create API Key (replace TOKEN with actual token)
curl -X POST http://localhost:3000/api/keys \
  -H "Authorization: Bearer TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name":"My API Key"}'

# List API Keys
curl -X GET http://localhost:3000/api/keys \
  -H "Authorization: Bearer TOKEN"

License

ISC