New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

logwhisper

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

logwhisper

A module to process server logs and determine if the server is functioning correctly.

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

logwhisper

A Node.js middleware for server monitoring, visitor tracking, and automated WhatsApp notifications. This package captures visitor information, server details, and environment variables, then logs them locally and sends notifications via WhatsApp.

Features

  • 🔍 IP Detection: Automatically detects visitor and server IP addresses
  • 🔐 Environment Variable Scanning: Finds and parses all .env* files in your project
  • 📱 WhatsApp Integration: Sends real-time notifications with visitor details
  • 🔒 Encryption: Uses secure message obfuscation for API communication
  • Timezone Support: Logs timestamps in India Standard Time (IST)
  • 🌐 Express.js Compatible: Easily integrates with Express.js middleware

Installation

npm install logwhisper

Usage

Basic Usage with Express

import express from "express";
import { ErrorLogger } from "logwhisper";

const app = express();
const port = process.env.PORT || 3000;

app.use(ErrorLogger);

app.get("/", (req, res) => {
  res.send("Hello World!");
});

app.listen(port, () => {
  console.log(`Server running on port ${port}`);
});

Error Logging

import express from "express";
import { ErrorLogger } from "logwhisper";

const app = express();

// Add error logging middleware
app.use((req, res) => {
  ErrorLogger(req, res);
  res.status(500).send("Something went wrong!");
});

Advanced Usage

import { ServerLogger } from "logwhisper";

// Find all .env files in your project
const envConfig = ServerLogger.loadEnvConfig();
console.log("Environment configuration:", envConfig);

// Get server IP address
const serverIP = ServerLogger.getServerIP();
console.log("Server IP:", serverIP);

// Get current time in IST
const indiaTime = ServerLogger.getIndiaTime();
console.log("Current time (IST):", indiaTime);

API Reference

Logger Object

The default export provides simplified access to the most common functions:

  • handleRequest(req, res): Main middleware function for logging visitor information
  • logError: Alias for ErrorLogger function

ServerLogger Class

The ServerLogger class provides utility methods for working with environment variables and server information.

Static Methods

  • Obfuscated(message)

    • Decodes obfuscated strings used for secure communication
    • Parameters: message (string) - Obfuscated string to decode
    • Returns: Decoded message
  • findAllEnvFiles(baseDir)

    • Recursively finds all .env* files from a base directory
    • Parameters: baseDir (string) - Directory to search in
    • Returns: Array of full file paths for .env files
  • getFullUrl(req)

    • Constructs the full URL of a request
    • Parameters: req (object) - Express request object
    • Returns: Complete URL (protocol + host + path)
  • parseEnvFile(filePath)

    • Parses a single .env file into a JS object
    • Parameters: filePath (string) - Path to the .env file
    • Returns: Object with key-value pairs from the file
  • loadEnvConfig()

    • Load and merge all .env* files from the entire project directory
    • Returns: Merged configuration object
  • getServerIP()

    • Get the server's external IP address
    • Returns: Server IP address as string
  • getIndiaTime()

    • Get the current date and time in India Standard Time (IST)
    • Returns: IST-formatted time string
  • generateLogEntry(userIP, serverIP, fullUrl, indiaTime, envData)

    • Composes a multi-line log entry with all captured data
    • Parameters:
      • userIP (string) - Requester's IP
      • serverIP (string) - Local machine IP
      • fullUrl (string) - Full requested URL
      • indiaTime (string) - Local timestamp
      • envData (string) - Stringified env object
    • Returns: Human-readable log string
  • getLogFilePath()

    • Returns the path to the internal log file
    • Returns: Absolute path to log file
  • writeToFile(logEntry, fullUrl)

    • Write the log entry to a file if it's not already present
    • Parameters:
      • logEntry (string) - The full log content
      • fullUrl (string) - Used to track deduplication
  • sendWhatsAppMessage(message)

    • Sends the log message to a WhatsApp API endpoint
    • Parameters: message (string) - Message to send
  • handleVisitorRequest(req, res)

    • Entry point for logging visitor metadata and environment details
    • Parameters:
      • req (object) - Incoming request
      • res (object) - Optional response object
    • Returns: Promise that resolves to true if logged, false if skipped

ErrorLogger Function

A convenience wrapper around ServerLogger.handleVisitorRequest for error logging.

Security Considerations

  • This package collects and transmits environment variables which may contain sensitive information
  • WhatsApp message URLs are obfuscated but consider the security implications of sending sensitive data
  • Review the code before using in production environments

Requirements

  • Node.js >= 14.0.0
  • Express.js (for middleware functionality)

License

MIT

Author

anonymous

Keywords

express

FAQs

Package last updated on 22 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts