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

@dabomb/async_store

v0.0.1

Published

Async Store is a small wrap around Node's [`AsyncLocalStorage`](https://nodejs.org/api/async_context.html) API that lets you define Async Vars. An Async Var is an object which holds a value that's bound to the current execution context. In other words, it

Downloads

5

Readme

Async Store

Async Store is a small wrap around Node's AsyncLocalStorage API that lets you define Async Vars. An Async Var is an object which holds a value that's bound to the current execution context. In other words, it enables dependency injection with minimal overhead.

You can get started by installing async_store via NPM:

npm i async_store@dabomb/async_store

Usage Examlpes

Logging

Use a file logger in development, otherwise use a Kafka logger.

/* main.ts */

import { AsyncScope } from 'async_store';
import { app } from './app';
import { logger } from './logger';

async function main() {
  await new AsycScope().run(async () => {
    await logger.init();

    try {
      await app.run();
    }
    catch (error) {
      logger.error(error);
      process.exitCode ??= 1;
    }
  });
}

void main();
/* app/index.ts */

import { createServer } from 'http';
import { logger } from './logger';

export const app = {
  run() {
    const server = createServer(router);

    server.listen(process.env.PORT, process.env.HOST, () => {
      logger.info(`Server is listening on ${process.env.HOST}:${process.env.PORT}`);
    });

    return new Promise((resolve, reject) => {
      server.on('close', resolve);
      server.on('error', reject);
    });
  }
};

function router(req: http.IncomingMessage, res: http.ServerResponse) {
  logger.info('Incoming request', req.socket.address());

  // handle request ...
}
/* logger/index.ts */

import { AsyncVar } from 'async_store';
import { ILogger } from './logger';

const LoggerVar = new AsyncVar<ILogger>('Logger');

export const logger = {
  init() {
    let logger: ILogger;

    if (process.env.NODE_ENV === 'development') {
      const { FileLogger } = await import('./file_logger');
      logger = new FileLogger();
    }
    else {
      const { KafkaLogger } = await import('./kafka_logger');
      logger = new KafkaLogger();
    }

    LoggerVar.set(logger);
  },

  info(message: string) {
    LoggerVar.get().info(message);
  },

  warn(message: string) {
    LoggerVar.get().warn(message);
  },

  error(message: string) {
    LoggerVar.get().error(message);
  },
}

Routing

Extract account data from current request.

/* app.ts */

import express from 'express';
import { AsyncScope } from 'async_store';
import { authRouter } from './routers/auth_router';
import { accountRouter } from './routers/account_router';
import { publicRouter } from './routers/public_router';

export const app = express();

app.use((req, res, next) => {
  new AsyncScope().run(next);
});

appRouter.use('/auth', authRouter);
appRouter.use('/account', accountRouter);
appRouter.use('/public', publicRouter);
/* routers/account_router.ts */

import { Router } from 'express';
import { auth } from '../auth';

export const accountRouter = Router();

accountRouter.use((req, res, next) => {
  auth.init(req);

  if (!auth.account) {
    res.status(401);
    return;
  }

  next();
})

accountRouter.get('/', (req, res) => {
  res.json(auth.account);
});

// more routes ...
/* auth.ts */

import { AsyncVar } from 'async_store';
import { parse as parseCookie } from 'cookie';
import * as http from 'http';
import { Account } from './accout';

const AuthVar = new AsyncVar<{ account: Account }>('Auth');

const auth = {
  get account() {
    return AuthVar.exists() ? AuthVar.get().account : null;
  },

  init(req: http.IncomingMessage) {
    const cookieHeader = req.headers['cookie'];
    if (!cookieHeader) return null;

    const cookies = parseCookie(cookieHeader);
    const jwt = cookies['jwt'];
    if (!jwt) return null;

    const payload = jwt.split('.')[1];
    if (!payload) return null;

    const decodedPayload = Buffer.from(payload, 'base64').toString('utf-8');
    const account = Account.parse(JSON.parse(decodedPayload));

    Auth.set({ account });
  },
}

License

MIT