@eloritzkovitz/server-essentials
v1.0.14
Published
A collection of reusable libraries, utilities and helpers to accelerate Node.js server development.
Maintainers
Readme
Server Essentials
A collection of reusable utilities, middleware, and services for Node.js server projects.
This package helps you quickly add common server functionality such as authentication, messaging, file handling, logging, and more.
Features
Auth
- JWT authentication middleware
- Role-based authorization
- OTP generation and email delivery
- Token management and refresh token verification
- Request helpers
Configuration
- Centralized config loader with environment variable support
Files
- File upload middleware for Express
- File handling helpers
Formatting
- Date formatting and manipulation
- Number formatting and manipulation
- String formatting and manipulation
- Helpers for masking emails/phones and formatting IDs/codes
Gateway
- Proxy middleware for API gateway scenarios
Logging
- Winston-based logger with environment-aware configuration
- Colorized console and file logs in development
- JSON console logs in production/Docker
- HTTP request logging middleware
- Log helpers for error handling, request tracing, and masking sensitive data
Messaging
- RabbitMQ service for notifications and RPC
- Firebase Cloud Messaging sender
Server
- Health check, ping, and API info endpoints
Validation
- Input validation helpers (email, phone, password, etc.)
Installation
npm install @eloritzkovitz/server-essentialsUsage
Import what you need from the package.
Configuration
Set required environment variables in your .env file:
# RabbitMQ
RABBITMQ_URL=amqp://localhost
# SMTP for OTP
SMTP_HOST=smtp.example.com
SMTP_PORT=465
[email protected]
SMTP_PASS=yourpassword
[email protected]
# JWT
TOKEN_SECRET=your_jwt_secret
# Firebase Messaging
GOOGLE_APPLICATION_CREDENTIALS=path/to/serviceAccount.jsonTesting & Coverage
Run all tests and view coverage reports using Jest:
npm test
npx jest --coverageThe coverage report will be generated in the coverage/ folder (which is gitignored by default).
You can add or run tests for any module in the test/ directory.
Tests are organized to match the source code structure for easy maintenance.
API Documentation
Full API documentation is available in the docs folder and can be viewed online via GitHub Pages.
License
MIT
