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

@fast2fa/fast2fa-js

v1.0.3

Published

JavaScript package for the easiest and quickest two-factor authentication service [Fast2fa](https://fast2fa.com).

Readme

fast2fa-js

JavaScript package for the easiest and quickest two-factor authentication service Fast2fa.

Installation

npm install @fast2fa/fast2fa-js

Usage

Once you have registered your account at Fast2fa, you can use the following examples to verify phone numbers (for example, for login purposes).

Pick the use case that best suits your needs:

Server only (with keeping the client connection open)

Here is an example of how to use the verifyAndWaitForStatus function in a server-only context, where you can keep the client connection open until the user has verified their phone number (for example, on your own servers). The example uses promises, but you can use async/await if you prefer.

const fast2fa = require('@fast2fa/fast2fa-node');
// ...
router.get('/login', (req, res) => {
    // ... Code to check user credentials, and get user phone number

    fast2fa.verifyAndWaitForStatus({
        id: '...', // Fast2fa ID
        accesstoken: '...', // Fast2fa Access Token
        phone: phone, // User phone number
        timeout: 2 * 60 * 1000 // Timeout in milliseconds (default: 2 minutes)

    }).then(result => {
        if (!result) {
            // User did not verify their phone number
            return;
        }

        // All is good. User has verified their phone number.
    }).catch(error => {
        if (error.message === 'timeout') {
            // User did not verify their phone number within the timeout period
            return;
        }
    });
});

Server initiates, client polls (directly with Fast2fa API) for status

Here is an example of how to use the verify function in the server, and then use the waitForStatus function in the client to poll for the status of the verification. This is useful in situations where it might be inconvenient to keep the client connection open until the user has verified their phone number (for example, in cloud functions and other serverless environments).

Note: You can pass a payload that the client will receive in the waitForStatus function only if the user approved the two-factor authentication (For example, you can pass an authentication token that the client can use to authenticate itself for further requests, only after the user has verified their phone number).

Server

const fast2fa = require('@fast2fa/fast2fa-node');
// ...
router.get('/login', async (req, res) => {
    // ... Code to check user credentials, and get user phone number

    const msgId = await fast2fa.verify({
        id: '...', // Fast2fa ID
        accesstoken: '...', // Fast2fa Access Token
        phone: phone, // User phone number
        payload: {
            accesstoken: '...', // Access token that the client will receive only after the user has verified their phone number
        }
    });

    // Send the msgId for polling in the client
    res.status(200).json({ msgId });
});

Client

const fast2fa = require('@fast2fa/fast2fa-js');

async function onLogin() {
    const { msgId } = await fetch('/login').then(res => res.json());

    fast2fa.waitForStatus({
        msgId: '...', // msgId received from the server
        timeout: 2 * 60 * 1000 // Timeout in milliseconds (default: 2 minutes)
    }).then(result => {
        if (!result || result.status !== 'approved') {
            // User did not verify their phone number
            return;
        }

        // All is good. User has verified their phone number.
        // You can now use the payload that the user has approved.
        const { accesstoken } = result.payload;
    });
}

Server initiates, client polls for status using your own servers

Here is an example of how to use both the verify and the getStatus functions in the server, while the client triggers the polling process. This is useful in situations where it might be inconvenient to keep the client connection open until the user has verified their phone number (for example, in cloud functions and other serverless environments), and you want to perform more server tasks after the user has verified their phone number.

Server

const fast2fa = require('@fast2fa/fast2fa-js');

router.get('/login', async (req, res) => {
    // ... Code to check user credentials, and get user phone number

    const msgId = await fast2fa.verify({
        id: '...', // Fast2fa ID
        accesstoken: '...', // Fast2fa Access Token
        phone: phone, // User phone number
    });

    // Send the msgId for polling in the client
    res.status(200).json({ msgId });
});

router.get('/login-step2', async (req, res) => {
    const { msgId } = req.query;
    const result = await fast2fa.getStatus({ msgId });

    if (result.status === 'pending') {
        res.status(200).json({ status: 'pending' });
        return;
    } else if (result.status === 'denied') {
        res.status(401).json({ status: 'denied' });
        return;
    } else if (result.status !== 'approved') {
        res.status(500).json({ status: 'unknown-error' });
        return;
    }

    // All is good. User has verified their phone number. Perform next tasks.
    // ...
});

Client

async function onLogin() {
    const { msgId } = await fetch('/login').then(res => res.json());

    let status;
    while (true) {
        status = await fetch(`/login-step2?msgId=${msgId}`).then(res => res.json());
        if (status.status === 'pending') {
            await new Promise(res => setTimeout(res, 1000));
        } else {
            break;
        }
    }

    // ...
}