npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@arcari/open-audit

v1.0.7

Published

> A lightweight, pluggable audit log library for Node.js — log user actions to Postgres, MySQL, MongoDB, SQLite, or files.

Readme

🕵️‍♂️ OpenAudit

A lightweight, pluggable audit log library for Node.js — log user actions to Postgres, MySQL, MongoDB, SQLite, or files.


🚀 Features

  • ✅ Simple API: OpenAudit.init() and OpenAudit.log()
  • ✅ Multiple storage adapters:
    • PostgreSQL (pg)
    • MySQL / MariaDB (mysql2)
    • SQLite (better-sqlite3)
    • MongoDB (mongodb)
    • File-based (JSON files)
  • ✅ Automatic table/collection creation on init
  • ✅ Debug/logging support with color output
  • ✅ Lightweight — no ORM, no runtime bloat

📦 Install

npm install @arcari/open-audit

You'll also need to install the database driver for your chosen adapter, or pass your custom, check the examples:

# For PostgreSQL
npm install pg

# For MySQL/MariaDB
npm install mysql2

# For MongoDB
npm install mongodb

# For SQLite
npm install better-sqlite3

🛠️ Basic Usage

import { OpenAudit } from "open-audit";

await OpenAudit.init({
  provider: "postgresql", // 'mysql' | 'mongodb' | 'sqlite' | 'file'
  url: "postgres://user:pass@localhost:5432/mydb",
  debug: true,
  driver: "pg",
});

await OpenAudit.log({
  actorId: "user_123",
  action: "user.login",
  entity: "user",
  entityId: "user_123",
  metadata: {
    ip: "127.0.0.1",
    userAgent: "Mozilla/5.0",
  },
});

📁 Examples

Explore the examples folder in this repository to find practical usage examples demonstrating:

  • How to initialize and configure the library
  • Usage of all supported adapters (PostgreSQL, MySQL, SQLite, MongoDB, File, and custom)
  • Sample configurations and connection setups
  • Logging and audit event recording in action

These examples serve as a hands-on guide to quickly get started with the library in your projects.


⚙️ Configuration per Adapter

🔹 PostgreSQL and pg driver

{
  provider: 'postgresql',
  url: 'postgres://user:pass@host:port/db',
  debug?: boolean,
  driver: "pg"
}

🔹 MySQL / MariaDB and mysql2 driver

{
  provider: 'mysql',
  url: 'mysql://user:pass@host:port/db',
  debug?: boolean,
  driver: "mysql2"
}

🔹 MongoDB and mongo driver

{
  provider: 'mongodb',
  url: 'mongodb://localhost:27017',
  dbName?: string,          // default: 'audit'
  collectionName?: string,  // default: 'audit_events'
  debug?: boolean,
  driver: "mongo"
}

🔹 SQLite and better-sqlite3 driver

{
  provider: 'sqlite',
  path?: string,   // default: './audit.sqlite'
  debug?: boolean,
  driver: "better-sqlite3"
}

🔹 File (JSON-based logging)

{
  provider: 'file',
  path?: string,   // default: './audit_logs'
  debug?: boolean
}

Each log is written to a daily .json file:

audit_logs/
  └── 2025-07-09.json

🧪 Event Format

type AuditEvent = {
  actorId?: string;
  action: string;
  entity?: string;
  entityId?: string;
  metadata?: object;
};

Example:

await OpenAudit.log({
  actorId: "user_1",
  action: "post.create",
  entity: "post",
  entityId: "post_123",
  metadata: {
    title: "Hello World",
    tags: ["intro", "welcome"],
  },
});

🧱 Example SQL Schema (Postgres/MySQL)

CREATE TABLE audit_events (
  id SERIAL PRIMARY KEY,
  timestamp TIMESTAMPTZ DEFAULT now(),
  actor_id TEXT,
  action TEXT NOT NULL,
  entity TEXT,
  entity_id TEXT,
  metadata JSONB
);

SQLite stores metadata as a stringified JSON column.


📣 Roadmap / Coming Soon

  • [ ] Web dashboard to view audit logs
  • [ ] CLI for searching and exporting logs
  • [ ] Custom adapter support (plugin interface)
  • [ ] Type-safe schema validation
  • [ ] Option for per-tenant database separation

🤝 Contributing

Pull requests are welcome! For major changes, open an issue first to discuss what you'd like to change.

To get started locally:

git clone https://github.com/yourname/open-audit.git

cd open-audit

npm install

npm run dev

📄 License

MIT — Tomas Lachmann
Built in 🇨🇿 Czechia with ❤️