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

in-memory-otp

v1.4.0

Published

A lightweight JavaScript package for generating and validating OTP (One Time Password) maintaining high performance using in-memory database.

Readme

In the name of Allah, the Most Gracious, the most Merciful

What is it?

in-memory-otp is a lightweight JavaScript package for generating and validating OTP (One Time Password) maintaining high performance using on demand in-memory database. Feel free to open issues and/or creating pull requests.

Installation

Install in-memory-otp by running any of the following commands at terminal

npm install in-memory-otp

npm install in-memory-otp --save

Usage

// Importing the OTP functionality
const otp = require('in-memory-otp');

// Start OTP functionality
otp.startOTPTimer(new Date().getTime());

//Set otp digits as 6
otp.setOTPDigits(6);

// Generate OTP for user1
const user1OTP = otp.generateOTP('user1', 5);
console.log('Generated OTP for user1 is:', user1OTP);

// Generate OTP for user2
const user2OTP = otp.generateOTP('user2', 5);
console.log('Generated OTP for user2 is:', user2OTP);

// Validate user1 OTP
otp.validateOTP('user1', user1OTP);
// Validate user2 OTP
otp.validateOTP('user2', user2OTP); 

Functions Description

startOTPTimer(currentTime)

This function starts the OTP functionality in the program. It only requires time at which the functionality to begin. OTPs will be verified correctly if this function is called before generating any OTP. Its good to start the OTP functionality using the following line

otp.startOTPTimer(new Date().getTime());

otp.setOTPDigits(noOfDigits)

This function set the number of digits of OTP generated. This is an optional method, by default the number of digits is set to 4.

otp.generateOTP(uniqueIndentifierOfUser, expirayTimeInMinutes)

This function generates and returns the OTP against the unique identifier of the user/customer. Its first parameter is the identifier and send parameter is the amount of time (in minutes) for which we want to generate OTP.

otp.validateOTP(uniqueIndentifierOfUser, OTP);

This function validates the OTP generated against the customer/user. It returns true if the correct OTP is passed as send parameter with in the expiray time, allocated while creating the OTP. If the time is expired and/or incorrect OTP is passed, then false is returned.

Benefits

  • No database is required.
  • OTP will be created only when it is necessary.
  • OTP will be removed from the memory (RAM) when its time is expired.
  • Efficient and fast because no read/write operation is performed on the disk.