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

souq-error-handler

v1.1.8

Published

A simple error handler with Opsgenie integration

Downloads

7

Readme

ErrorHandler

This project provides a customizable error handling library for Node.js applications. ErrorHandler sends alerts using Opsgenie, logs error messages to a file, and can be easily integrated into other projects.

Usage

To use the ErrorHandler in your project, first install it as a dependency:

Add the following values do your .env file

OPSGENIE_GENERIC_CHANNEL_API_KEY=your_api_key
PRODUCTION_CRITICAL_SLACK_ALERT_CHANNEL_ID=PRODUCTION_CRITICAL_SLACK_ALERT_CHANNEL_ID
LOG_FILE_PATH=/path/to/error.log
npm install --save souq-error-handler

Then, import and use the ErrorHandler in your project:

const ErrorHandler = require('errorHandler');

// Initialize ErrorHandler instance
const errorHandler = new ErrorHandler(
  process.env.OPSGENIE_GENERIC_CHANNEL_API_KEY || '',
  process.env.LOG_FILE_PATH || 'error.log'
);

// Log error to file
errorHandler.logError('Logging an example error message into the error.log');

// Send error to team devices with specified severity
errorHandler.slackAlert('Logging an example critical error message into the slack', 'critical').catch((err) => {
    console.error('A critical slack alert:', err);
});

errorHandler.slackAlert('Logging an example moderate error message into the slack', 'moderate').catch((err) => {
    console.error('A moderate slack alert:', err);
});

// Send error to team devices and send generic alert
errorHandler.genericAlert('Logging an example error directly to team devices').catch((err) => {
    console.error('A generic alert:', err);
});

Running Tests

To run tests, execute the following command:

npm test

Linting

This project uses ESLint for linting. To fix linting issues, run:

npm run lint --fix

Further Development

  1. Clone this repository:
git clone https://github.com/yourusername/errorHandler.git
  1. Install dependencies:
npm install
  1. Copy the .env.example file to create a new .env file:
cp .env.example .env
  1. Update the .env file with your API keys, recipients, and other configuration values.

  2. (optional) Run the example usage script to see what happens:

node src/example_usage.js

Folder Structure

|-- .env
|-- .env.example
|-- .eslintignore
|-- .eslintrc.json
|-- .gitignore
|-- README.md
|-- index.js
|-- package-lock.json
|-- package.json
|-- src
|   |-- errorHandler.js
|   |-- example_usage.js
|-- tests
    |-- errorHandler.test.js