Skip to main content

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:
npm install http-ledger

Verify Installation

After installation, verify that HTTP Ledger is installed correctly:
npm list http-ledger
You should see the installed version in the output.

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:
const logger = require('http-ledger');
const express = require('express');

const app = express();
app.use(logger());

ES Modules

For modern projects using ES modules:
import logger from 'http-ledger';
import express from 'express';

const app = express();
app.use(logger());

TypeScript

For TypeScript projects with full type support:
import express from 'express';
import logger, { ApiLoggerOptions, LogData, LogLevel } from 'http-ledger';

const app = express();

const options: ApiLoggerOptions = {
  logBody: true,
  logResponse: true,
  maskFields: ['password', 'token']
};

app.use(logger(options));
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 logger middleware function
  • Named exports: TypeScript types and interfaces
    • ApiLoggerOptions: Configuration options interface
    • LogData: Log data structure interface
    • LogLevel: Log level type ('info' | 'warn' | 'error')
    • IpInfo: IP information interface
    • Timestamp: 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 your tsconfig.json includes:
{
  "compilerOptions": {
    "moduleResolution": "node",
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true
  }
}

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:
  1. Ensure the package is installed in your node_modules directory
  2. Delete node_modules and reinstall: rm -rf node_modules && npm install
  3. Check that your Node.js version is 18.0.0 or higher: node --version

TypeScript Type Errors

If you encounter TypeScript errors:
  1. Ensure you’re using TypeScript 5.x or higher
  2. Check that your tsconfig.json has proper module resolution settings
  3. 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.

Build docs developers (and LLMs) love