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
bash
npm install pms_md
`
$3
Install only the database drivers you need:
`bash
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
$3
`javascript
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!)
$3
Add a complete monitoring dashboard to your app with just one line of code:
`javascript
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);
`
$3
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
$3
โ
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
$3
`javascript
// 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
`
$3
Visit http://localhost:3000/ after starting your server to see the beautiful UI!
๐ Complete UI Integration Guide โ
---
๐๏ธ Database Monitoring
$3
`javascript
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);
`
$3
`javascript
const { Pool } = require('pg');
const pool = new Pool({
host: 'localhost',
database: 'mydb',
user: 'postgres',
password: 'password'
});
monitor.registerDatabase('postgres', 'postgresql', pool);
`
$3
`javascript
const mysql = require('mysql2/promise');
const pool = mysql.createPool({
host: 'localhost',
user: 'root',
password: 'password',
database: 'mydb'
});
monitor.registerDatabase('mysql', 'mysql2', pool);
`
$3
`javascript
const mongoose = require('mongoose');
await mongoose.connect('mongodb://localhost:27017/mydb');
monitor.registerDatabase('mongodb', 'mongoose', mongoose.connection);
`
$3
`javascript
const Redis = require('ioredis');
const redis = new Redis({
host: 'localhost',
port: 6379
});
monitor.registerDatabase('redis', 'redis', redis);
`
$3
`javascript
const sqlite3 = require('sqlite3');
const db = new sqlite3.Database('./mydb.sqlite');
monitor.registerDatabase('sqlite', 'sqlite', db);
`
$3
`javascript
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
$3
1. Enable 2-Step Verification in your Google Account
2. Generate App Password: https://myaccount.google.com/apppasswords
3. Configure environment variables:
`bash
EMAIL_USER=your-email@gmail.com
EMAIL_APP_PASSWORD=your-16-char-app-password
`
$3
`javascript
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']
}
}
});
`
$3
- โ
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
$3
`javascript
// Automatic error tracking and email notifications
app.use(monitor.errorMiddleware());
`
$3
`javascript
// Log all HTTP requests with sanitization
app.use(monitor.requestLogger());
`
$3
`javascript
// Handle 404 errors
app.use(monitor.notFoundHandler());
`
---
๐ Health Endpoints
$3
`javascript
app.get('/health', monitor.healthCheckEndpoint());
`
Response:
`json
{
"status": "healthy",
"timestamp": "2025-11-17T12:00:00.000Z",
"uptime": 3600,
"databases": {
"mssql": "connected",
"redis": "connected"
}
}
`
$3
`javascript
app.get('/health/info', monitor.healthInfoEndpoint());
`
Response:
`json
{
"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:
`javascript
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
$3
`javascript
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
$3
#### 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: Promisemonitor.getAllDatabaseStats()
Get statistics for all registered databases.
Returns: Promisemonitor.setupGracefulShutdown(server)
Setup graceful shutdown with email notifications.
Parameters:
- server (object) - HTTP server instance
$3
#### monitor.errorMiddleware()
Express middleware for error handling.
#### monitor.requestLogger()
Express middleware for request logging.
#### monitor.notFoundHandler()
Express middleware for 404 errors.
$3
#### 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:
`bash
node test-all-databases.js
`
Test Coverage:
- โ
Package loading
- โ
Monitor instantiation
- โ
Database registration (all 13+ types)
- โ
Health checks
- โ
Statistics retrieval
- โ
Peer dependencies
---
๐ Documentation
- Database Support Guide - Complete guide for all 13+ databases
- Quick Reference - Quick setup examples
- Changelog - Version history and updates
- Release Notes - Latest release information
---
๐ง Troubleshooting
$3
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
$3
1. Verify database driver is installed
2. Check connection credentials
3. Ensure database server is running
4. Review database-specific logs
$3
1. Adjust monitoring.interval to reduce frequency
2. Reduce logging.maxFiles` retention period