A comprehensive Express.js utility package for request information, user behavior tracking, and beautiful console logging.
- 🔍 Request Information - Detailed insights about incoming requests
- 👁️ DevTools Detection - Track when browser dev tools are opened
- 🖱️ Mouse Movement Analysis - Detect bot-like behavior
- 📊 Enhanced Logging - Beautiful, colorful console output with detailed metrics
npm install express-raw
const express = require('express');
const { expressLogger, getRequestInfo, detectDevTools, mouseTracker } = require('express-raw');
const app = express();
const logger = new expressLogger();
app.use(logger.middleware());
// Start server with enhanced logging
app.listen(3000, () => {
logger.serverStart(3000);
});
app.get('/info', (req, res) => {
const info = getRequestInfo(req);
res.json(info);
});
const detector = detectDevTools();
const script = detector.getScript();
const tracker = mouseTracker({ trackingTime: 5000 });
const script = tracker.getScript();
const logger = new expressLogger({
enabled: {
heartbeat: true,
requests: true,
responses: true,
errors: true
},
heartbeatInterval: 5000
});
{
enabled: {
server: true, // Server start logs
requests: true, // Request logs
responses: true, // Response logs
errors: true, // Error logs
heartbeat: true // System status logs
},
heartbeatInterval: 10000, // Heartbeat frequency in ms
colors: true // Colored output
}
{
trackingTime: 5000 // Duration to track mouse (ms)
}
[2024-11-25T19:38:20.177Z] ⚡ [SERVER] Server started
Port: 3000
Environment: development
NodeVersion: v22.11.0
Memory: 8MB
[2024-11-25T19:38:25.123Z] ○ [INFO] GET /test
IP: ::1
UserAgent: Mozilla/5.0
RequestId: 1
ActiveConnections: 1
[2024-11-25T19:38:25.234Z] ♥ [HEARTBEAT] System Status
Uptime: 5s
Requests: 1
HeapUsed: 12MB
RequestsPerSecond: 0.2
MIT
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request
const express = require('express');
const { expressLogger, detectDevTools, mouseTracker, getRequestInfo } = require('express-raw');
const app = express();
const logger = new expressLogger();
// Basic middleware
app.use(express.json());
app.use(logger.middleware());
// Request info endpoint
app.get('/info', (req, res) => {
res.json(getRequestInfo(req));
});
// Page with tracking
app.get('/', (req, res) => {
const detector = detectDevTools();
const tracker = mouseTracker({ trackingTime: 5000 });
res.send(`
<!DOCTYPE html>
<html>
<head><title>Tracking Demo</title></head>
<body>
<h1>Behavior Tracking Demo</h1>
<div id="results"></div>
<script>${detector.getScript()}</script>
<script>${tracker.getScript()}</script>
</body>
</html>
`);
});
app.listen(3000, () => logger.serverStart(3000));
{
"method": "GET",
"path": "/test",
"headers": {
"user-agent": "Mozilla/5.0...",
"accept": "text/html..."
},
"ip": "::1",
"query": {},
"protocol": "http"
}
{
"isBot": false,
"confidence": 0.82,
"metrics": {
"speedVariance": 0.245,
"angleVariance": 0.089,
"straightLines": 12
}
}
-
Logger Configuration
- Enable only needed features
- Adjust heartbeat interval based on needs
- Use colors in development, disable in production
-
Performance
- Mouse tracking should be time-limited
- Consider rate limiting for production
- Clean up event listeners
-
Security
- Don't log sensitive information
- Validate inputs
- Set appropriate CORS headers
Common issues and solutions:
// Fix: Logger not showing colors
const logger = new expressLogger({ colors: true });
// Fix: Heartbeat too frequent
const logger = new expressLogger({ heartbeatInterval: 30000 });
// Fix: Missing request body
app.use(express.json());
app.use(logger.middleware());
- [ ] Request Rate Limiting
- [ ] Custom Log Formats
- [ ] Log File Output
- [ ] Metrics Dashboard
- [ ] Performance Profiling
For issues and feature requests, please use the GitHub issue tracker.
Made with ♥ by ZeX