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 🙏

© 2025 – Pkg Stats / Ryan Hefner

otp-gen-agent

v1.1.6

Published

A small and secure one time password (otp) generator for Javascript based on nanoid

Readme

otp-gen-agent: Secure One-Time Password Generation for Nodejs

A small and secure one time password (otp) generator for Javascript based on nanoid.

NPM

contributions welcome npm version License

If you find this utility library useful, you can buy me a coffee to keep me energized for creating libraries like this.

What is OTP-Gen-Agent?

otp-gen-agent is a lightweight, flexible Node.js library designed to simplify one-time password (OTP) generation for authentication systems. With mobile number verification becoming the standard authentication method across India and many other regions, this utility provides developers with reliable OTP generation capabilities.

Installation

npm install otp-gen-agent --save

Core Features

  • Simple API: Generate secure OTPs with minimal code
  • Customizable: Control OTP length and character set
  • Bulk Generation: Create multiple OTPs in a single operation
  • Lightweight: No bloated dependencies
  • Promise-based: Modern async/await support
  • Webhook Support: Trigger webhooks for OTP generation events

Usage

Mobile number has become the defacto user authentication mechanism in India and hence, OTP generation is a very common phenomena. This is a small utility lib to generate OTP.

Standard OTP Generation

Generate a standard 6-digit numeric OTP:

const { otpGen } = require('otp-gen-agent');

const otp = await otpGen(); // '344156'  (OTP length is 6 digit by default)
  • Default OTP lenght: 6
  • Default characters set: 0123456789 (Numeric [0-9])

Custom OTP Generation

Create OTPs with custom length and character sets:

const { customOtpGen } = require('otp-gen-agent');

const otp = await customOtpGen({length: 4, chars: 'abc123'}); // 'a3c1'

Arguments:

  • options: optional
    • length: custom otp length
    • chars: custom characters

You can customise the OTP length and also the characters to be used for OTP generation.

  • Default OTP lenght is 6.
  • Default characters used to generate OTP is 0123456789

Bulk OTP Generation

Generate multiple OTPs in a single operation:

const { bulkOtpGen } = require('otp-gen-agent');

const otp = await bulkOtpGen(2); // Array of otps: ['344156', '512398']
const { bulkOtpGen } = require('otp-gen-agent');

const otp = await bulkOtpGen(2, {length = 5, chars: 'abcd123'} ); // Array of otps: ['312b3', 'bcddd']

Arguments:

  • num: number of OTPs to be generated in bulk
  • opts: optional argument
    • length: custom otp length (default: 6)
    • chars: custom characters (default: 0123456789)

When to Use Bulk Generation

The bulk generation feature is particularly useful when:

  • Pre-generating OTPs for upcoming authentication requests
  • Testing authentication systems with multiple users
  • Creating backup validation codes

Webhook Support

The library provides webhook support to track OTP generation events. You can set up a webhook handler to receive notifications when OTPs are generated:

const { otpGen, bulkOtpGen, setWebhookHandler, WEBHOOK_EVENTS } = require('otp-gen-agent');

// custom webhook handler function
const webHookHandler = async (event, data) => {
  switch (event) {
    case WEBHOOK_EVENTS.OTP_GENERATED:
      console.log('Single OTP generated:', data.otp);
      break;
    case WEBHOOK_EVENTS.OTP_BULK_GENERATED:
      console.log(`Generated ${data.count} OTPs:`, data.otps);
      break;
  }
};

// Set up webhook handler
setWebhookHandler(webHookHandler);

// Generate OTPs - webhook will be triggered automatically
const otp = await otpGen(); // Triggers OTP_GENERATED event
const bulkOtps = await bulkOtpGen(3); // Triggers OTP_BULK_GENERATED event

Webhook Events:

  • otp-generated: Triggered when a single OTP is generated
    • Payload: { otp: string }
  • bulk-otp-generated: Triggered when multiple OTPs are generated
    • Payload: { count: number, otps: string[] }

Features:

  • Automatic webhook triggering for all OTP generation methods
  • Error handling for webhook failures
  • Type-safe event handling
  • Customizable webhook handler implementation

Test

npm run test

Learn More

For detailed documentation and implementation examples, read our comprehensive guide on A One Time Password (OTP) generator

License

This project is licensed under the MIT License - see the LICENSE file for details

MIT

If you find this utility library useful, you can buy me a coffee to keep me energized for creating libraries like this.

Tech Blog

Read my personal blog on various tech topics at Tech Insights: Personal Tech Blog