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

metered

v0.3.1

Published

Library for API creators to add middleware to authenticate and record usage

Readme

metered

Helps SaaS businesses and API developers with metered billing, validating API usage to your API, tracking usage, and syncing with your Stripe dashboard.

Features

  • Configure where to find the API key / customer / product
  • Mention the product name or Configure which part of the url/query/body/post/url indicates a product
  • Validate API keys of all requests that a customer sends, through a middleware
  • Increase usage records
  • No dependencies
  • Fine grained control of when to increase usage
  • Light weight. Soon to support TCP,UDP apart from HTTP
  • Contact Metered for an API key to automatically create Customer, Subscriptions, Plans, And Usage Records based on how your customers are hitting your API, into your Stripe Dashboard

Usage

Eg 1: Example of directly recording customer's use of your API

Here we also capture version, and decide the entire url will be the product

const Metered = require('metered');

meter = new Metered.Config({
    apikey:'YOUR_API_KEY'                                 // Do not share
});

app.post('/alien/wire', (req,res) => {

		meter.customer = 'alien-bank';                    // Set customer
		meter.subscription = 'inter-galactic-transfer';   // Set subscription
		
		// At this point we know your customer 
		// has sent a valid API key
		res.send({success: true, 
		          message:'Done. Thanks.'                 // Your logic
		});               
	
		
		//increase usage by 1 for the given customer, product
		Metered.Usage.Increment	(meter)                   // Increase Usage
 	}
});	
    

Eg 2: Getting usage validated and recorded, before your logic

Here we also capture version, and decide the entire url will be the product

const Metered = require('metered');

meter = new Metered.Config({
    apikey:'YOUR_API_KEY'                                 // Do not share
});

app.get('/api/vision/detect/:confidence', 

	// This is a middleware
	// Here we validate and increment if validated 
	// even before your logic
	Metered.Auth.Increment(meter,{
		 apikey   : Metered.Params.ByHeader('x-apikey'),  // Validate api-key
    	 product  : Metered.Params.ByUrl(),               // product = full path
    	 version  : Metered.Params.ByParam('version')     // Also capture version
    	                                                  // & then Increment
	}),

	(req,res,next) => {
		// At this point we know your customer 
		// has sent a valid API key
		res.send({message:'Your new Balance is ',
					bal: req.metered.response.balance     // End, display balance
		});             
		
 	}
});

Eg 3: First validating, using balance to your logic, and then incrementing usage by 2% of filesize of a download

Here is a more detailed example that has

const Metered = require('metered');

meter = new Metered.Config({
    apikey:'YOUR_API_KEY'                                 // Do not share
});

app.get('/download/:product', 

	// We can ask the meter to parse out params
	// from the url, query, body, url or a header
	Metered.Auth.Validate(meter,{
		 apikey   : Metered.Params.ByHeader('apikey'),    // Validate api-key
    	 product  : Metered.Params.ByParam('product')     // Parse product
	}),

		(req,res,next) => {
		var product = req.params.product;

		// At this point we know your customer 
		// has sent a valid API key
		if (allGood){
			myRedirectTo(req.params.product);             // Your logic

			// Store a custom variable in the same request 
			req.fileSizeLogic = myTwoPercentLogic(req.body);
	
			// and call next middleware to be used there
			next();                                       // Continue to usage
		}else{
			// passing an argument to next indicates an error
			next('That file does not exist');             // Stops if !allGood
		}
 	},

	// we seperately call middleware Metered.Usage.Increment
	// since we called Metered.Auth.Validate
	// which would not have incremented earlier
	// So now we increment usage by 2% of the file size
	Metered.Usage.Increment	By({
		amount: fileSizeLogic*0.02,                       // Complex Usage
		currency: 'usd'
	});

});

Upcoming Features

  • Choice of TCP/UDP/HTTP protcol

Who do I talk to?

  • Raise an issue or feature request