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

env-console-override

v1.0.1

Published

A package to customize console outputs based on the environment

Downloads

8

Readme

env-console-override

A flexible NPM package to customize console outputs with custom messages, ASCII art, or custom functions based on a whitelist of environments.

Installation

To install this package, use npm:

npm install env-console-override

Basic Usage

const overWriteConsoleMethods = require('env-console-override');

overWriteConsoleMethods({
  logOptions: {
    customMessage: 'Production Log Message',
    asciiArt: '    A     K    K\n   A A    K K  \n  AAAAA   KK   \n A     A  K K  \nA       A K   K'
  },
  whitelistEnvs: ['production']
});

console.log("This will show a custom log message in production.");

Options

Main Options

  • logOptions: Configuration for console.log.
  • warnOptions: Configuration for console.warn.
  • errorOptions: Configuration for console.error.
  • infoOptions: Configuration for console.info.
  • whitelistEnvs: Array of environments where the console methods should be overwritten (default: ['production']).
  • env: Current environment (default: process.env.NODE_ENV).

Method Options

  • customMessage: Custom message to display (default: 'Default Message').
  • asciiArt: ASCII art to display.
  • customFunction: Custom function to execute. Receives the original console method as the first argument and the original arguments as the rest.
  • clearOnly: If true, only clears the console without displaying any message (default: false).

Example Usage

const overWriteConsoleMethods = require('env-console-override');

// Example in production environment
process.env.NODE_ENV = 'production';

overWriteConsoleMethods({
  logOptions: {
    customMessage: 'Production Log Message',
    asciiArt: '    A     K    K\n   A A    K K  \n  AAAAA   KK   \n A     A  K K  \nA       A K   K'
  },
  warnOptions: {
    customMessage: 'Warning!',
  },
  errorOptions: {
    customFunction: (originalError, ...args) => {
      originalError('Custom Error Function Executed with args:', ...args);
    }
  },
  infoOptions: {
    customMessage: 'Information Message',
  },
  whitelistEnvs: ['production', 'staging']
});

console.log("This will show a custom log message in production or staging.");
console.warn("This will show a custom warning message in production or staging.");
console.error("This will execute a custom error function in production or staging.");
console.info("This will show a custom information message in production or staging.");

// Example in development environment
process.env.NODE_ENV = 'development';

overWriteConsoleMethods({
  logOptions: {
    customMessage: 'Development log message',
        clearOnly: true
  },
  whitelistEnvs: ['production']
});

console.log("This will log normally in development.");