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

@ahmadnassri/debug

v2.0.1

Published

Debugging utility using environment regex, matches node core's debugging technique

Downloads

46

Readme

Node Debug

Debugging utility using environment regex, matches node core’s debugging technique

license release semantic

Install

npm install @ahmadnassri/debug

Usage

Follows the exact same behaviour as util.debuglog with some minor differences:

  • checks for both DEBUG and NODE_DEBUG environment variables
  • checks environment variables every time debuglog() is called (vs. on require/ import)
  • regex matching in the environment variables
  • no global caching (you can change the behaviour every time debuglog() is called)
  • optionally include performance time in output
  • optionally include process id in output

debug(section, options)

| Option | Type | Description | Default | |-----------|--------------|------------------------------------|-----------------| | section | <string> | The section name | | | logger | <Function> | Custom logger function | console.debug | | pid | <boolean> | Include process id in output | true | | perf | <boolean> | Include performance time in output | false |

Returns: <Function> The logging function

The debuglog() method is used to create a function that conditionally writes debug messages to stderr based on the existence of the DEBUG or NODE_DEBUG environment variables. If the section name appears within the value of that environment variable, then the returned function operates similar to console.debug(). If not, then the returned function is a no-op.

Environment Variables

| Variable | Description | |----------------|--------------------------------------------------------------------------------------------------| | DEBUG | A comma-separated list of section names to enable | | NODE_DEBUG | A comma-separated list of section names to enable | | DEBUG_COLORS | Enable/disable colors in output (will also respect Node's NO_COLORS & NODE_DISABLE_COLORS) | | DEBUG_PERF | Include/exclude performance time in output (⚠️ will overwrite perf option) | | DEBUG_PID | Include/exclude process id in output (⚠️ will overwrite pid option) |

Examples
const debuglog = require('@ahmadnassri/debug')
const debug = debuglog('foo')

debug('hello from foo [%d]', 123)

If this program is run with DEBUG=foo or NODE_DEBUG=foo in the environment, then it will output something like:

FOO 3245: hello from foo [123]

where 3245 is the process id. If it is not run with that environment variable set, then it will not print anything.

Multiple Sections

Multiple section names may be specified in the environment variable, separated by commas, or spaces.

Example
DEBUG=fs,net,tls

Regex Matching

section names in the environment variable, can also be a regex string:

Example
const debuglog = require('@ahmadnassri/debug')
const primary = debuglog('foo:primary')
const secondary = debuglog('foo:secondary')

primary('primary logger')
secondary('secondary logger')
$ NODE_DEBUG=foo:.* node app.js

FOO:PRIMARY 28382 primary logger
FOO:SECONDARY 28382 secondary logger
Get Fancy
$ DEBUG="(F|O)+:.*" node app.js

FOO:PRIMARY 28274 primary logger
FOO:SECONDARY 28274 secondary logger

remove PID

const debuglog = require('@ahmadnassri/debug')
const debug = debuglog('foo', { pid: false })

debug('hello from foo [%d]', 123)
FOO: hello from foo [123]

add Performance Time

const debuglog = require('@ahmadnassri/debug')
const debug = debuglog('foo', { perf: true })

debug('hello from foo [%d]', 123)
FOO 3245 (65ms) hello from foo [123] +0ms

Disable Colors

$ DEBUG_COLORS=0 node app.js

Disable Performance Time

$ DEBUG_PERF=0 node app.js

Author: Ahmad Nassri • Twitter: @AhmadNassri