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

konsol

v0.1.4

Published

Drop-in replacement for console with verbosity option

Downloads

10

Readme

konsol

License NPM Package NPM Downloads Build Status Test Coverage Code Climate Dependency Status devDependency Status

Author: Kurt Pattyn.

Konsol is a drop-in replacement for the node.js console. It adds the ability to enable and disable the output.
Suppression of the output can be controlled at run-time through the enable and disable static methods, or at start-time through the use of the KONSOL environment variable.

Motivation

When using modules, one often wants to see debug output from those modules.
During normal operation these messages should not be shown. But during development these messages can be very helpful for debugging.
Also during production it can be very helpful to be able to also get log output from included modules (e.g. in case of troubleshooting).
By using Konsol you can log messages just like with console from within your own modules, but Konsol adds the capability to enable or surpress its output.
By default output is disabled.

Installation

$ npm install konsol

or

$ npm install konsol --production

for a production only installation (no tests, documentation, ...).

Usage

  var konsol = require("konsol")("mymodule");
  ...
  //we use konsol instead of console to do our logging
  konsol.log("...");  //or info, warn, err, ...
  
  module.exports = mymodule;

Running node mymodule.js will generate no output (default behaviour).
When we run KONSOL=mymodule node mymodule.js the output will enabled and written the stdout.

Output can also programmatically enabled and disabled:

  var Konsol = require("konsol");
  Konsol.enable("mymodule");
  var mm = require("mymodule");

In the above example, the output of mymodule will be visible.

API

Konsol(moduleName)

Used in a (sub)module for logging. Registers moduleName with Konsol and returns a Konsol logger.

Parameters

  • moduleName (String, required): name of the module; this name should match the name by which the module is known to the end-user

Although not strictly required, it is good practice to use the same name as the name by which the module is known to the end-user. In the case of Konsol for instance, this would be konsol.

Example

  var konsol = require("konsol")("mymodule");

  konsol.log("The sky is blue.");
  //can also use .info, .warn, .error, .dir, .time, .timeEnd

[static] Konsol.enable(moduleName)

Enables output for the given moduleName.

Parameters

  • moduleName (String, required): name of the module to enable output for

Example

  var myModule = require("mymodule");
  var Konsol = require("konsol");

  Konsol.enable("mymodule");
  //from now, all output of mymodule will be redirected to the console.

[static] Konsol.disable(moduleName)

Disables output for the given moduleName.

Parameters

  • moduleName (String, required): name of the module to disable output for

Example

  var myModule = require("mymodule");
  var Konsol = require("konsol");

  Konsol.disable("mymodule");
  //from now, all output of Konsol will be suppressed.

KONSOL Environment Variable

By default, all Konsol output is suppressed. Output can be enabled either by calling Konsol.enable() or by setting the KONSOL environment variable.
E.g. calling Konsol.enable("mymodule") is the same as starting node with KONSOL=mymodule node myapp.js.

The difference between setting the KONSOL environment variable and calling Konsol.enable() is that the enable() method can change the output at run-time.

The KONSOL environment variable is a comma- and/or space-separated list of modules for which to enable the output.
E.g.
KONSOL=mymodule, yourmodule node app.js
is the same as
KONSOL=mymodule yourmodule node app.js

Tests

Unit Tests

$ npm test

Unit Tests with Code Coverage

$ npm run test-cov

This will generate a folder coverage containing coverage information and a folder coverage/lcov-report containing an HTML report with the coverage results.

$ npm run test-ci

will create a folder coverage containing lcov formatted coverage information to be consumed by a 3rd party coverage analysis tool. This script is typically used on a continuous integration server.

Checkstyle

Executing

$ npm run check-style

will run the jscs stylechecker against the code.

Static Code Analysis

Executing

$ npm run code-analysis

will run jshint to analyse the code.

Code Documentation

Executing

$ npm run make-docs

will run jsdoc to create documentation.

License

MIT