JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q30434F
  • License ISC

Comprehensive monitoring solution for Node.js applications with error tracking, health checks, multi-database support (MongoDB, PostgreSQL, MySQL, MSSQL, SQLite, Redis, Cassandra, Elasticsearch, DynamoDB, Neo4j, CouchDB), and multi-channel notifications

Package Exports

  • pms_md
  • pms_md/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pms_md) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

๐Ÿš€ PMS_MD - Comprehensive Node.js Monitoring Solution

npm version License: ISC Node.js

Production-ready monitoring solution for Node.js applications with comprehensive database support, error tracking, health checks, and multi-channel notifications.


โœจ Features

  • ๐ŸŽจ Beautiful UI Dashboard - One-line integration with stunning monitoring UI (NEW!)
  • ๐Ÿ—„๏ธ 13+ Database Support - MongoDB, PostgreSQL, MySQL, MariaDB, MSSQL, SQLite, Redis, Cassandra, Elasticsearch, DynamoDB, Neo4j, CouchDB, Sequelize
  • ๐Ÿ“ง Email Notifications - Automatic alerts for errors, crashes, and database failures
  • ๐Ÿ“Š Health Monitoring - System resources (CPU, Memory), API errors, database connections
  • ๐Ÿ”” Multi-Channel Alerts - Email, Slack, and custom webhooks
  • ๐Ÿ“ Advanced Logging - Winston-based logging with daily rotation and sanitization
  • ๐Ÿ›ก๏ธ Graceful Shutdown - Proper cleanup with email notifications on server shutdown
  • ๐ŸŽฏ Express Integration - Middleware for error handling, request logging, and health endpoints
  • ๐Ÿ“ˆ Metrics & Analytics - Historical metrics tracking and dashboard endpoints

๐Ÿ“ฆ Installation

npm install pms_md

Optional Database Drivers

Install only the database drivers you need:

# SQL Databases
npm install pg                          # PostgreSQL
npm install mysql2                      # MySQL
npm install mariadb                     # MariaDB
npm install mssql                       # MSSQL (SQL Server)
npm install sqlite3                     # SQLite

# NoSQL Databases
npm install mongoose                    # MongoDB
npm install nano                        # CouchDB
npm install cassandra-driver            # Cassandra

# Cache & Search
npm install ioredis                     # Redis
npm install @elastic/elasticsearch     # Elasticsearch

# Cloud Databases
npm install @aws-sdk/client-dynamodb    # DynamoDB

# Graph Databases
npm install neo4j-driver                # Neo4j

# ORM
npm install sequelize                   # Sequelize (MySQL, PostgreSQL, SQLite, MSSQL)

๐Ÿš€ Quick Start

Basic Setup

const express = require('express');
const NodeMonitor = require('pms_md');

const app = express();

// Initialize monitor
const monitor = new NodeMonitor({
  app: {
    name: 'my-app',
    environment: 'production'
  },
  notifications: {
    email: {
      enabled: true,
      smtp: {
        host: 'smtp.gmail.com',
        port: 587,
        secure: false,
        auth: {
          user: process.env.EMAIL_USER,
          pass: process.env.EMAIL_APP_PASSWORD
        }
      },
      from: process.env.EMAIL_USER,
      recipients: ['admin@example.com']
    }
  }
});

// Add middleware
app.use(monitor.requestLogger());
app.use(monitor.errorMiddleware());

// Health endpoints
app.get('/health', monitor.healthCheckEndpoint());
app.get('/health/info', monitor.healthInfoEndpoint());

// Start monitoring
monitor.start();

// Start server
const server = app.listen(3000, () => {
  console.log('Server running on port 3000');
});

// Graceful shutdown with email notifications
monitor.setupGracefulShutdown(server);

module.exports = app;

๐ŸŽจ Beautiful Monitoring UI (NEW!)

One-Line Integration ๐Ÿš€

Add a complete monitoring dashboard to your app with just one line of code:

const express = require('express');
const NodeMonitor = require('pms_md');

const app = express();

const monitor = new NodeMonitor({
  app: { name: 'My App' }
});

// ===== ONE LINE TO ENABLE ENTIRE UI! =====
monitor.serveUI(app);

monitor.start();
app.listen(3000);

What You Get

After calling monitor.serveUI(app), you get:

  • ๐Ÿ  Home Page - / - Navigation hub with quick links
  • ๐Ÿ“Š Dashboard - /monitor/dashboard - Complete monitoring overview
  • ๐Ÿ’š Health Check - /health - Live health status with auto-refresh
  • ๐Ÿ“ˆ Metrics - /monitor/metrics - Interactive charts (CPU, Memory)
  • ๐Ÿ“‹ Status - /monitor/status - Real-time status overview
  • ๐Ÿšจ Error Logs - /monitor/error-logs - Error tracking

Features

โœ… Zero Configuration - Works out of the box โœ… No File Copying - Everything served from node_modules โœ… Beautiful Design - Modern, responsive UI โœ… Real-time Updates - Auto-refresh dashboards โœ… Interactive Charts - Powered by Chart.js โœ… Dark/Light Theme - User preference support โœ… Content Negotiation - Supports both HTML and JSON

Advanced Configuration

// Custom base path
monitor.serveUI(app, {
  basePath: '/monitoring',
  appName: 'Production API',
  enableErrorLogs: true
});

// UI now available at:
// http://localhost:3000/monitoring/
// http://localhost:3000/monitoring/dashboard

Screenshots

Visit http://localhost:3000/ after starting your server to see the beautiful UI!

๐Ÿ“š Complete UI Integration Guide โ†’


๐Ÿ—„๏ธ Database Monitoring

MSSQL (SQL Server)

const sql = require('mssql');

const pool = await sql.connect({
  server: 'localhost',
  database: 'mydb',
  user: 'sa',
  password: 'password',
  options: {
    encrypt: true,
    trustServerCertificate: true
  }
});

monitor.registerDatabase('mssql', 'mssql', pool);

PostgreSQL

const { Pool } = require('pg');

const pool = new Pool({
  host: 'localhost',
  database: 'mydb',
  user: 'postgres',
  password: 'password'
});

monitor.registerDatabase('postgres', 'postgresql', pool);

MySQL / MariaDB

const mysql = require('mysql2/promise');

const pool = mysql.createPool({
  host: 'localhost',
  user: 'root',
  password: 'password',
  database: 'mydb'
});

monitor.registerDatabase('mysql', 'mysql2', pool);

MongoDB

const mongoose = require('mongoose');

await mongoose.connect('mongodb://localhost:27017/mydb');
monitor.registerDatabase('mongodb', 'mongoose', mongoose.connection);

Redis

const Redis = require('ioredis');

const redis = new Redis({
  host: 'localhost',
  port: 6379
});

monitor.registerDatabase('redis', 'redis', redis);

SQLite

const sqlite3 = require('sqlite3');
const db = new sqlite3.Database('./mydb.sqlite');

monitor.registerDatabase('sqlite', 'sqlite', db);

Cassandra

const cassandra = require('cassandra-driver');

const client = new cassandra.Client({
  contactPoints: ['localhost'],
  localDataCenter: 'datacenter1'
});

await client.connect();
monitor.registerDatabase('cassandra', 'cassandra', client);

See complete database guide โ†’


๐Ÿ“Š Supported Databases

Database Type Package Status
MongoDB NoSQL mongoose โœ…
PostgreSQL SQL pg โœ…
MySQL SQL mysql2 โœ…
MariaDB SQL mariadb โœ…
MSSQL SQL mssql โœ…
SQLite SQL sqlite3 โœ…
Redis Cache ioredis โœ…
CouchDB NoSQL nano โœ…
Cassandra NoSQL cassandra-driver โœ…
Elasticsearch Search @elastic/elasticsearch โœ…
DynamoDB Cloud @aws-sdk/client-dynamodb โœ…
Neo4j Graph neo4j-driver โœ…
Sequelize ORM sequelize โœ…

๐Ÿ“ง Email Notifications

Gmail Setup

  1. Enable 2-Step Verification in your Google Account
  2. Generate App Password: https://myaccount.google.com/apppasswords
  3. Configure environment variables:
EMAIL_USER=your-email@gmail.com
EMAIL_APP_PASSWORD=your-16-char-app-password

Configuration

const monitor = new NodeMonitor({
  notifications: {
    email: {
      enabled: true,
      smtp: {
        host: 'smtp.gmail.com',
        port: 587,
        secure: false,
        auth: {
          user: process.env.EMAIL_USER,
          pass: process.env.EMAIL_APP_PASSWORD
        }
      },
      from: process.env.EMAIL_USER,
      recipients: ['admin@example.com', 'team@example.com']
    }
  }
});

Notification Types

  • โœ… Server Errors - Uncaught exceptions and unhandled rejections
  • โœ… Database Failures - Connection loss and recovery
  • โœ… Graceful Shutdown - Server shutdown notifications
  • โœ… API Errors - HTTP 500 errors and critical failures

๐ŸŽฏ Express Middleware

Error Handling

// Automatic error tracking and email notifications
app.use(monitor.errorMiddleware());

Request Logging

// Log all HTTP requests with sanitization
app.use(monitor.requestLogger());

404 Handler

// Handle 404 errors
app.use(monitor.notFoundHandler());

๐Ÿ“ˆ Health Endpoints

Basic Health Check

app.get('/health', monitor.healthCheckEndpoint());

Response:

{
  "status": "healthy",
  "timestamp": "2025-11-17T12:00:00.000Z",
  "uptime": 3600,
  "databases": {
    "mssql": "connected",
    "redis": "connected"
  }
}

Detailed Health Info

app.get('/health/info', monitor.healthInfoEndpoint());

Response:

{
  "status": "healthy",
  "timestamp": "2025-11-17T12:00:00.000Z",
  "uptime": 3600,
  "system": {
    "cpu": 45.2,
    "memory": {
      "used": 512,
      "total": 8192,
      "percentage": 6.25
    }
  },
  "databases": {
    "mssql": {
      "status": "connected",
      "type": "mssql",
      "version": "Microsoft SQL Server 2019...",
      "connections": 10
    }
  }
}

๐Ÿ›ก๏ธ Graceful Shutdown

Automatically send email notifications when your server shuts down:

const server = app.listen(3000);

// Setup graceful shutdown with email notifications
monitor.setupGracefulShutdown(server);

Features:

  • โœ… Sends email notification on shutdown
  • โœ… Closes all database connections
  • โœ… Stops all monitoring intervals
  • โœ… Handles SIGTERM and SIGINT signals
  • โœ… Prevents memory leaks

๐Ÿ“ Advanced Configuration

Full Configuration Example

const monitor = new NodeMonitor({
  app: {
    name: 'my-production-app',
    environment: 'production',
    version: '1.0.0'
  },
  monitoring: {
    enabled: true,
    interval: 60000,  // Check every 60 seconds
    systemMetrics: true,
    apiErrors: true
  },
  database: {
    enabled: true,
    checkInterval: 30000,  // Check every 30 seconds
    queryTimeout: 5000,
    consecutiveFailuresThreshold: 3
  },
  notifications: {
    email: {
      enabled: true,
      smtp: {
        host: 'smtp.gmail.com',
        port: 587,
        secure: false,
        auth: {
          user: process.env.EMAIL_USER,
          pass: process.env.EMAIL_APP_PASSWORD
        }
      },
      from: process.env.EMAIL_USER,
      recipients: ['admin@example.com']
    },
    slack: {
      enabled: false,
      webhookUrl: process.env.SLACK_WEBHOOK_URL
    }
  },
  logging: {
    level: 'info',
    directory: './logs',
    maxFiles: '14d',
    maxSize: '20m',
    sanitize: true
  }
});

๐Ÿ“š API Reference

Core Methods

monitor.start()

Start all monitoring services.

monitor.stop()

Stop all monitoring services.

monitor.registerDatabase(name, type, connection)

Register a database for monitoring.

Parameters:

  • name (string) - Unique identifier for the database
  • type (string) - Database type (e.g., 'mssql', 'postgresql', 'mongodb')
  • connection (object) - Database connection object

monitor.getDatabaseStats(name)

Get statistics for a specific database.

Returns: Promise

monitor.getAllDatabaseStats()

Get statistics for all registered databases.

Returns: Promise

monitor.setupGracefulShutdown(server)

Setup graceful shutdown with email notifications.

Parameters:

  • server (object) - HTTP server instance

Middleware Methods

monitor.errorMiddleware()

Express middleware for error handling.

monitor.requestLogger()

Express middleware for request logging.

monitor.notFoundHandler()

Express middleware for 404 errors.

Endpoint Methods

monitor.healthCheckEndpoint()

Express endpoint handler for basic health check.

monitor.healthInfoEndpoint()

Express endpoint handler for detailed health information.

monitor.dashboardEndpoint()

Express endpoint handler for monitoring dashboard.


๐Ÿงช Testing

Run the comprehensive test suite:

node test-all-databases.js

Test Coverage:

  • โœ… Package loading
  • โœ… Monitor instantiation
  • โœ… Database registration (all 13+ types)
  • โœ… Health checks
  • โœ… Statistics retrieval
  • โœ… Peer dependencies

๐Ÿ“– Documentation


๐Ÿ”ง Troubleshooting

Email Notifications Not Working

  1. Check Gmail App Password is correct (16 characters, no spaces)
  2. Verify 2-Step Verification is enabled
  3. Check environment variables are loaded
  4. Review logs in ./logs directory

Database Connection Failures

  1. Verify database driver is installed
  2. Check connection credentials
  3. Ensure database server is running
  4. Review database-specific logs

High Memory Usage

  1. Adjust monitoring.interval to reduce frequency
  2. Reduce logging.maxFiles retention period
  3. Disable unused monitoring features

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


๐Ÿ“„ License

ISC License - see LICENSE file for details


๐Ÿ‘ค Author

Manish Proses


๐Ÿ™ Acknowledgments

Built with:


๐Ÿ“Š Version History

v1.0.3 (Latest)

  • โœ… Added MSSQL (SQL Server) support
  • โœ… Added MariaDB support
  • โœ… Added SQLite support
  • โœ… Added CouchDB support
  • โœ… Added Cassandra support
  • โœ… Added Elasticsearch support
  • โœ… Added DynamoDB support
  • โœ… Added Neo4j support
  • โœ… Comprehensive documentation
  • โœ… 100% test coverage

v1.0.2

  • โœ… Enhanced MySQL2 support (v2 and v3)
  • โœ… Added Sequelize ORM support
  • โœ… Improved peer dependencies

v1.0.1

  • โœ… Initial release
  • โœ… MongoDB, PostgreSQL, MySQL, Redis support
  • โœ… Email notifications
  • โœ… Health monitoring

๐Ÿš€ What's Next?

Planned features for future releases:

  • TypeScript definitions
  • Prometheus metrics export
  • Custom alerting rules
  • Performance profiling
  • Distributed tracing

Made with โค๏ธ for the Node.js community