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 🙏

© 2024 – Pkg Stats / Ryan Hefner

req-meta-middleware

v0.1.4

Published

Express middleware for parsing request metadata (referrer, geo-ip, ..)

Downloads

15

Readme

req-meta-middleware

An Express middleware for parsing various request metadata. The following data are parsed from the request object:

Installation

npm:

npm install req-meta-middleware

yarn:

yarn add req-meta-middleware

Usage

Add req-meta-middleware to your middleware stack. Note that we need to await for the middleware to initialize.

import meta from 'req-meta-middleware';

const app = express();
// ...
app.use(await meta());

All parsed information is stored at req.meta.

app.use((req: Request, res: Response, next: NextFunction) => {
  console.log(req.meta.referrer);
 });

Options

You can also specify options while initializing the middleware.

const options = {
   // Domains of the server (default: [])
  internalDomains: ['foo.com'],
  // When set to true, req IP will not be parsed and req.meta.ip will be null. (default: false)
  skipIP: false,
  // When set to true, the referrer database will be fetched from the web. (default: true)
  // Otherwise, local database stored in data/referers.json will be used.
  webReferralDB: true,
  // Cron schedule string for updating the referrer database.
  // This is only effective when webReferralDB is true. (default: '0 0 0 * * * *')
  updateSchedule: '0 0 0 * * * *'
};
server.use(meta(options));

See the node-cron docs for the cron schedule syntax.

Parsing after response

If req.meta isn't used for building responses, it may be faster in response time to parse the request after sending the response. (eg. only using metadata for referral stats) In that case, use later to parse metadata after the response has been sent.

const handler = (data) => {
  console.log(data);
};
server.use(await meta.later(handler, options));

The middleware will first call next() to further process the request, then parse and callback after the response has been sent.