A comprehensive API logging and monitoring system for Node.js + Express applications that tracks, analyzes, and visualizes API requests in real-time. Built with Node.js, Express, and MongoDB, this system provides detailed insights into your API's performance, errors, and usage patterns.
Note: Currently supports Node.js + Express applications only. Support for other frameworks (like NestJS) will be added in future releases.
- Node.js (v14 or higher)
- Express.js application
- MongoDB database
- Track all API requests in real-time
- Monitor response times, session logs, status codes, and request/response bodies
- Filter logs by endpoint, date, time, and status code
- Visual metrics for total requests, average response time, and error rates
- Interactive charts showing status code trends
- System resource monitoring (CPU, Memory, Uptime)
- Top 5 slowest endpoints analysis
- View complete request and response details
- Inspect headers and session logs
- Copy request/response data with one click
- Navigate through paginated log history
- Role-based access control (Admin/Dev roles)
- Secure authentication with JWT
- Protected dashboard and logs access
- Session management
- Install the package:
npm install api-logger
- Configure your Express application:
const express = require("express");
const app = express();
const { createExpressLogger } = require("api-logger");
// Important: Place other middleware before createExpressLogger
app.use(function (req, res, next) {
logger.info(`[${req.method}] ${req.baseUrl}${req.url}`);
next();
});
// Initialize the logger after other middleware
createExpressLogger({
app,
mongoUri: "mongodb://localhost:27017/your-database",
beginswith: ["/api"], // Optional: Only log requests starting with these paths
specifics: ["/auth"], // Optional: Exclude these paths from logging
});
- Navigate to
/logs/login
in your browser - Log in with your credentials:
- First user to log in becomes an admin
- Subsequent users are assigned dev role
- Password is set on first login
- View real-time metrics and system stats
- Monitor API performance trends
- Track system resource usage
- Identify slow endpoints
- Browse all API requests
- Filter logs by:
- Endpoint
- Date and time
- Status code
- View paginated results
- Sort and search through logs
- View complete request details
- Inspect request and response bodies
- Check headers and session logs
- Copy data for debugging
- Manage your account
- Log out securely
The createExpressLogger
function accepts the following parameters:
app
: Your Express application instancemongoUri
: MongoDB connection stringbeginswith
: Array of path prefixes to log (optional)specifics
: Array of paths to exclude from logging (optional)
The order of middleware in Express is crucial. If you're using other logging middleware, make sure to place it before createExpressLogger
. For example:
// Correct order:
app.use(function (req, res, next) {
logger.info(`[${req.method}] ${req.baseUrl}${req.url}`);
next();
});
createExpressLogger({
/* config */
});
// Incorrect order (may cause issues):
createExpressLogger({
/* config */
});
app.use(function (req, res, next) {
logger.info(`[${req.method}] ${req.baseUrl}${req.url}`);
next();
});
- All dashboard routes are protected by JWT authentication
- First-time login creates an admin account
- Subsequent logins create dev accounts
- Session tokens expire after 1 hour
- Secure cookie-based authentication
- Add support for NestJS applications
- Add support for other Node.js frameworks
- Implement real-time WebSocket updates
- Add custom alert configurations
- Support for multiple database types
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.