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

@natsubate/secrets-token-generator

v1.0.0

Published

A lightweight utility for generating cryptographically secure random tokens in Node.js, similar to Python's secrets module.

Downloads

104

Readme

@natsubate/secrets-token-generator npm version

A lightweight utility for generating cryptographically secure random tokens in Node.js, similar to Python's secrets module.

Install

npm install @natsubate/secrets-token-generator

Usage

import { tokenBytes, tokenHex, tokenUrlSafe } from "@natsubate/secrets-token-generator";

const tokenByBuffer = tokenBytes(32); // 32bytes secure random bytes

const tokenByHex = tokenHex(32); // 32bytes secure random HEX string
console.log(tokenByHex); // -> 7b6d3b21cd1a40b3baf2013c475247fa2c577bfef691e4661cce35fc846f328f

const tokenByUrlSafeBase64 = tokenUrlSafe(32); // 32bytes secure random by Base64URL
console.log(tokenByUrlSafeBase64); // -> 7H8lLtZ6A5C96rfpxtbsRiB2lmXj3ctukOM4kywRIwY

API

tokenBytes(bytes: number): Buffer

Generates a random value of the specified byte count using cryptographically secure pseudo-random number generator (CSPRNG) and returns the buffer.

  • bytes: number - Random bytes length (e.g., 32).
  • Returns: Buffer - Raw bytes.

tokenHex(bytes: number): string

Generates a random value of the specified byte length using CSPRNG and returns the HEX string.

  • bytes: number - Random bytes length (e.g., 32).
  • Returns: string - HEX encoded token.

tokenUrlSafe(bytes: number): string

Generates a random value of the specified byte length using CSPRNG and returns a Base64 URL string.

  • bytes: number - Random bytes length (e.g., 32).
  • Returns: string - Base64URL encoded token.

Supported Environments

  • Node.js 18 or later

TypeScript Type Definition

Included.

Security Notice

  • The implementation uses the Node.js standard module crypto.randomBytes.
  • While it can be used for security-critical purposes such as CSRF tokens, session IDs, and API keys, ensure the required entropy amount (byte length) is appropriately set according to your use case.
  • Also consider the storage and transmission methods for generated tokens (e.g., using HTTPS, setting the Secure cookie flag).

Notes

  • All functions are synchronous.

License

  • MIT License