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

bugwarden

v3.0.1

Published

BugWarden is an open-source Node.js module that guards your applications against bugs and errors. With integrated error handling and reporting, it ensures real-time monitoring of server-side issues, alerting you on services like Slack and email, helping y

Downloads

14

Readme

BugWarden

Enhance Your Express.js Logging with Colorful Status Codes and Detailed Logs

BugWarden is an npm package designed to make your Express.js application's logging more informative and visually appealing. It provides:

  • Colorful status code indications for easy log scanning
  • Detailed request-response logs, including response times
  • Middleware integration for effortless tracking of HTTP activity

Installation

To install BugWarden, use npm:

npm install bugwarden

Usage

  1. Require BugWarden in your Express.js application:
// Common JS method
const express = require("express");
const { bugwarden } = require("bugwarden");
const app = express();

// ES Module method
import express from "express";
import { bugwarden } from "bugwarden";
const app = express();
  1. Apply BugWarden as middleware:
// Enable JSON parsing middleware (if needed)
app.use(express.json());

// Integrate BugWarden middleware
app.use(bugwarden());
  1. Use options:
// Display all logs
app.use(bugwarden());

// Display all logs
app.use(bugwarden({ logging: true }));

// No logs
app.use(bugwarden({ logging: false }));

// Specific logging
app.use(bugwarden({ logging: ["method", "responseTime", "statusCode"] }));
  1. Trigger slack notifications on specific status codes on any routes you want
app.use(
  bugwarden({
    logging: true, // Enable / Disable logging
    configureSlackNotification: {
      // Slack notification configuration
      webhookUrl: "<webhook URL>",
      notificationConfig: [
        {
          onStatus: "5xx",
          message:
            {method} - {original-url} Failed with status code {status-code},
          routes: "all",
        },
      ],
    },
  })
);

// Status code examples
"all" for all status codes
"2xx" for all 200 status codes
"3xx" for all 300 status codes
"4xx,5xx" for all 400 and 500 status codes

// Route examples
"all" for all routes
"/api/user" for a specific route
"/api/user/*"  for all routes starting with "/api/user/
"/api/user,/api/admin,/api/public/*" multiple routes separated by comma ","

// Message properties
// For now bugwarden supports the following message properties
{ip}
{timestamp}
{method}
{original-url}
{http-version}
{status-code}
{content-length}
{referer}
{user-agent}
{response-time}
Example : {method} - {original-url} Failed with status code {status-code}
Notification : GET - /abc/def/xyz Failed with status code 503
  1. Define your routes and start your server:
app.get("/", (req, res) => {
  res.json("hello world");
});

app.listen(3002, () => {
  console.log("Listening on port 3002");
});

Features

paintShop(text, statusCode)

  • Colors text based on HTTP status code ranges for visual distinction in logs.
  • Parameters:
    • text: The text to be colored (string).
    • statusCode: The HTTP status code (number).
  • Returns: A string with the colored text.

BugWarden(req, res, next)

  • Middleware function for logging HTTP request details and response time.
  • Parameters:
    • req: The HTTP request object.
    • res: The HTTP response object.
    • next: The next middleware function.

Logging Details:

  • IP
  • Timestamp (UTC)
  • Method
  • OriginalUrl
  • HttpVersion
  • Status
  • Content-Length
  • Referrer
  • User-Agent
  • Response-Time

Example Log Output

IP: ::1
Timestamp: [Tue, 26 Dec 2023 12:00:00 GMT]
Method: GET
OriginalUrl: /
HttpVersion: HTTP/1.1
Status: 200
Content-Length: 12
Referrer: -
User-Agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36"
Response-Time: 5ms

Customize to Your Logging Needs

BugWarden offers a flexible way to enhance your Express.js logging experience. Feel free to tailor it to your specific requirements for optimal debugging and monitoring.