Installation
HTTP Ledger is available as an npm package and can be installed using your preferred package manager.Requirements
Before installing HTTP Ledger, ensure your environment meets these requirements:- Node.js: Version 18.0.0 or higher
- Express.js: Version 4.x or higher
- TypeScript (optional): Version 5.x or higher for TypeScript projects
Package Manager Installation
Choose your preferred package manager to install HTTP Ledger:Verify Installation
After installation, verify that HTTP Ledger is installed correctly:Module System Support
HTTP Ledger supports multiple module systems, so you can use it in any Node.js environment:CommonJS
For traditional Node.js projects using CommonJS:ES Modules
For modern projects using ES modules:TypeScript
For TypeScript projects with full type support:HTTP Ledger includes TypeScript type definitions out of the box. No need to install separate
@types packages.Package Exports
The package provides the following exports:- Default export: The
loggermiddleware function - Named exports: TypeScript types and interfaces
ApiLoggerOptions: Configuration options interfaceLogData: Log data structure interfaceLogLevel: Log level type ('info' | 'warn' | 'error')IpInfo: IP information interfaceTimestamp: Request/response timestamp interface
Bundle Information
HTTP Ledger is optimized for production use:- Zero dependencies: No external runtime dependencies
- Small bundle size: Minimal impact on your application’s bundle
- Tree-shakeable: Only includes the code you use
- Dual format: Provides both CommonJS and ES module builds
TypeScript Configuration
If you’re using TypeScript, HTTP Ledger works out of the box with no additional configuration. The package includes type definitions that will be automatically picked up by TypeScript. For optimal TypeScript support, ensure yourtsconfig.json includes:
Next Steps
Now that HTTP Ledger is installed, you’re ready to use it in your application:Quick Start
Get started with a working example
Troubleshooting
Module Not Found Error
If you encounter a “Cannot find module ‘http-ledger’” error:- Ensure the package is installed in your
node_modulesdirectory - Delete
node_modulesand reinstall:rm -rf node_modules && npm install - Check that your Node.js version is 18.0.0 or higher:
node --version
TypeScript Type Errors
If you encounter TypeScript errors:- Ensure you’re using TypeScript 5.x or higher
- Check that your
tsconfig.jsonhas proper module resolution settings - Try restarting your TypeScript language server
Express Version Compatibility
HTTP Ledger is designed for Express 4.x. If you’re using Express 5.x (currently in beta), the middleware should still work, but some features may behave differently.If you encounter any issues during installation, please check the GitHub repository for known issues or open a new issue.