code-alert
v0.1.0
Published
Lightweight Node.js utility for sending SMS alerts (via Twilio) on console events.
Maintainers
Readme
Code Alert
A simple, lightweight Node.js package for sending notifications (initially SMS) on console errors and warnings.
Installation
npm install code-alert
# or
yarn add code-alertQuick Start
Set Environment Variables: Create a
.envfile in your project root (add it to.gitignore!). You need your Twilio credentials and the recipient phone numbers.# .env TWILIO_ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx TWILIO_AUTH_TOKEN=your_auth_token_xxxxxxxxxxxxx TWILIO_FROM_NUMBER=+15551112222 CODE_ALERT_RECIPIENT_NUMBERS=+15551234567,+15559876543Initialize in your app: Call
initonce at startup, passing configuration options except for recipient numbers (which are read from the environment).// Load environment variables (e.g., using dotenv) import "dotenv/config"; import { init } from "code-alert"; async function startApp() { try { await init({ // Recipient numbers are now read from process.env.CODE_ALERT_RECIPIENT_NUMBERS notifyOn: ["error"], // Optional: Trigger on console.error (default) // Add other configurations like thresholds, rate limits here }); console.log("Code Alert Initialized!"); // ... rest of your application startup // Example: This will now potentially trigger an SMS (once implemented) console.error("Something went wrong!"); } catch (error) { console.error("Failed to initialize Code Alert:", error); process.exit(1); // Exit if init fails } } startApp();
Configuration
Configuration is primarily handled via environment variables and the init function.
Environment Variables
The following environment variables are required:
TWILIO_ACCOUNT_SID: Your Twilio Account SID.TWILIO_AUTH_TOKEN: Your Twilio Auth Token.TWILIO_FROM_NUMBER: Your Twilio phone number (must be capable of sending SMS) in E.164 format (e.g.,+15551112222).CODE_ALERT_RECIPIENT_NUMBERS: A comma-separated list of recipient phone numbers in E.164 format (e.g.,+15551234567,+15559876543).
init(config) Options
The init function accepts an optional configuration object:
notifyOn: (ConsoleLevel[]) - An array of console levels ('error','warn','info','log') that should potentially trigger notifications. Defaults to['error'].messageFormat: (string) - A template string for formatting the notification message. Placeholders like{{message}},{{level}}etc., will be added later. (Default format TBD).
(Threshold, rate limit, and context options will be added here as they are implemented)
Usage
_(Usage examples, including the explicit `
