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

authik

v1.0.0

Published

Lightweight OTP authentication using Fast2SMS (no external backend needed)

Readme

Authik 🔐

A simple, zero-dependency OTP authentication module that uses Fast2SMS API to send and verify OTPs.

🚀 Installation

npm install authik

✨ Usage

const { sendOTP, verifyOTP } = require("authik");

const phone = "+91XXXXXXXXXX";
const apiKey = "YOUR_PUBLIC_FAST2SMS_API_KEY"; // keep public if for demo

// Send OTP
sendOTP(phone, apiKey).then(console.log);

// Verify OTP
const result = verifyOTP(phone, "123456");
console.log(result);

Note: This uses an in-memory store (non-persistent). Don't use for production as-is. For production, use Redis or a DB-backed store.

📦 Features

  • Generate 6-digit OTPs
  • Send SMS via Fast2SMS
  • Verify OTPs with expiry logic
  • Works with Express or standalone

🔑 API Key Usage

If this is for open demos or dev playgrounds, you can use a public test key in your examples. But don't hardcode it inside the library — keep it as a parameter like this:

sendOTP(phone, "your-public-api-key")

📖 API Reference

sendOTP(phone: string, apiKey: string): Promise<object>

Sends an OTP to the specified phone number using Fast2SMS.

Parameters:

  • phone (string): Phone number with country code (e.g., "+911234567890")
  • apiKey (string): Your Fast2SMS API key

Returns: Promise that resolves to the SMS API response

verifyOTP(phone: string, otp: string): object

Verifies the OTP for the given phone number.

Parameters:

  • phone (string): Phone number used during OTP generation
  • otp (string): The OTP entered by the user

Returns: Object with success (boolean) and message (string)

🧠 Complete Example

const { sendOTP, verifyOTP } = require("authik");

const phone = "+911234567890";
const apiKey = "your-fast2sms-api-key";

async function handleOTPFlow() {
    try {
        // Send OTP
        const response = await sendOTP(phone, apiKey);
        console.log("OTP sent:", response);
        
        // Later, when user enters OTP
        const userEnteredOTP = "123456"; // from user input
        const result = verifyOTP(phone, userEnteredOTP);
        
        if (result.success) {
            console.log("✅ OTP verified successfully!");
            // Proceed with authentication
        } else {
            console.log("❌ OTP verification failed:", result.message);
        }
    } catch (error) {
        console.error("Error:", error);
    }
}

handleOTPFlow();

⚡ Express.js Integration

const express = require("express");
const { sendOTP, verifyOTP } = require("authik");

const app = express();
app.use(express.json());

const API_KEY = "your-fast2sms-api-key";

app.post("/send-otp", async (req, res) => {
    const { phone } = req.body;
    try {
        const result = await sendOTP(phone, API_KEY);
        res.json({ success: true, data: result });
    } catch (error) {
        res.status(500).json({ success: false, error: error.message });
    }
});

app.post("/verify-otp", (req, res) => {
    const { phone, otp } = req.body;
    const result = verifyOTP(phone, otp);
    res.json(result);
});

app.listen(3000, () => {
    console.log("Server running on port 3000");
});

🛡️ Security Notes

  • In-memory storage: OTPs are stored in memory and will be lost on server restart
  • Production usage: For production apps, integrate with Redis or a database
  • Rate limiting: Implement rate limiting to prevent OTP abuse
  • API key security: Keep your Fast2SMS API key secure and use environment variables
  • One-time use: OTPs are automatically deleted after verification or expiry

🔧 Configuration

Default OTP settings:

  • Length: 6 digits
  • Expiry: 5 minutes
  • Storage: In-memory (non-persistent)

📄 License

MIT © 2025 Om Bhayde

✨ Contributing

Pull requests, ideas, and suggestions are welcome! Feel free to open an issue or contribute to the project.

💬 Support

If you use Authik in your project, let me know — I'd love to feature it!


🪄 Pro Tips

  • Use environment variables for API keys: process.env.FAST2SMS_API_KEY
  • Implement proper error handling for SMS delivery failures
  • Add logging for security monitoring and debugging
  • Consider implementing OTP retry mechanisms with exponential backoff