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

express-cashu

v0.2.0

Published

Express JS cashu middleware

Readme

Express cashu middleware

npm version

Express middleware for cashu payments using NUT-24

Installation

npm install -s express-cashu

Usage

Add middleware function to express http routes

import express from 'express';
import { cashu } from 'express-cashu';

const app = express();

app.use('/', cashu({
    paymentCallback: async (token: string, _req: express.Request) => {
        console.log('Received payment', token);
    },
    trustedMints: ['https://mint.lnserver.com'],
    amount: 10,
    unit: 'sat',
    debug: true
}));

app.get('/', (_req, res) => {
    res.send('Payment received!');
});

Server responds with http 402 status code and X-Cashu header, containing the payment request creqA...

X-Cashu: creqAo2FhBWF1Y3NhdGFt...

The client sends a cashu token with the requested amount to pay for the service

X-Cashu: cashuBo2FteBlodHRwczovL...

Payment Example:

import { decodePaymentRequest, getEncodedTokenV4, Proof, Token, Wallet, } from '@cashu/cashu-ts';

payToServer();

async function payToServer() {
    const protectedApiUrl = 'http://localhost:3000';

    // try access the API resource
    const req = await fetch(protectedApiUrl);

    // decode the received payment request from the API resource
    const paymentRequest = req.headers.get('x-cashu');
    const decodedPaymentRequest = decodePaymentRequest(paymentRequest);
    const mintUrl = decodedPaymentRequest.mints[0];

    // Internal stored proofs
    let proofs: Proof[];
    let sentProofs: Proof[];

    // Init wallet
    const wallet = new Wallet(mintUrl);
    await wallet.loadMint();

    // Example: get proofs from cashu token
    const storedToken = 'cashuBo2FteBlo....';
    const decodedToken = wallet.decodeToken(storedToken);
    proofs = decodedToken.proofs;

    // now use your proofs and send the requested amount back to the resource
    const { keep, send } = await wallet.send(decodedPaymentRequest.amount, proofs);

    // update remaining proof list
    proofs = keep;

    // store sent proofs to redeem them back later, if the receiver does not claim them
    sentProofs = send;

    // create a token with proof list
    const token: Token = {
        mint: mintUrl,
        proofs: send
    };

    // encode the token as a cashu string
    const cashuString = getEncodedTokenV4(token);

    // finally pay the requested amount with encoded token
    await fetch(protectedApiUrl, {
        headers: {
            'x-cashu': cashuString
        }
    });
};

Test

Run test suite

npm test