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

cnysa

v0.6.0

Published

A tool for understanding async-hooks

Downloads

5

Readme

cnysa (unpronouncible) is a module that allows you to see information about what the async_hooks module is doing under the covers. AsyncResources and their lifecycle events are displayed neatly in rows (see bottom for examples).

Pre-Require Hook

Pre-require cynsa/register in your application:

node --require cynsa/register app.js

If cnysa.json exists in the current working directory, it will be used as the configuration passed to the Cnysa constructor as described below.

API

const { Cnysa } = require('cnysa');

new Cnysa()

Constructs a new Cnysa instance.

Cnysa#enable()

Starts recording async events.

Cnysa#disable()

Stops recording async events.

Cnysa#mark(tag?: string|number)

Generate a special AsyncResource with the given tag. If tag is not specified, a monotonically increasing number is assigned to it.

The special AsyncResource will be displayed as a single event in cyan. This is good for determining the current running async resource.

Cnysa#createAsyncSnapshot(options: CnysaSnapshotOptions)

  • options.width: Maximum number of characters to print on a single line before wrapping. Defaults to the current terminal width.
  • options.ignoreTypes: A string or RegExp to filter out AsyncResource types.
  • options.roots: A list of AsyncResource IDs that must be an ancestor of a given AsyncResource for it to be displayed. The default value, an empty list, is equivalent to specifying no constraint on ancestry.
  • options.padding: Number that represents the amount of space between each depicted event.
  • options.format: A string that represents how the output should be formatted. Currently, the available options are 'default' and 'svg' (which uses ansi-to-svg).

Returns a formatted async ancestry tree. Great for printing in the console.

All options are optional.

Cnysa#createAsyncStackTrace(options: CnysaStackTraceOptions)

  • options.ignoreTypes: A string or RegExp to filter out AsyncResource types.

Experimental. Returns a formatted async stack trace.

All options are optional.

Cnysa.get()

Gets the most recently constructed Cnysa instance. If none were constructed, one is constructed automatically and returned. Therefore, this method is guaranteed to return a Cnysa instance.

This is useful when it is unknown whether cnysa has been used earlier in the application, especially as a command-line require.

Understanding output

For each AsyncResource, a timeline will be printed, with a number of colored symbols:

  • Green * represents the async resource creation.
  • Red * represents its destruction.
  • Blue {...} represent running in an async scope.
  • Gray - indicates the lifetime of the resource creation, and is bookended by * symbols.
  • Cyan * represents a location where Cnysa#mark was called.

Examples

node --require cnysa/register -e "                 \
  fs.readFile('package.json', (err, contents) => { \
    require('cnysa').Cnysa.get().mark('hi');       \
  })"

example-readfile.svg