Build an audit log system in Node.js

Track key user and system actions with an audit log in Node.js using Operational for detailed event insights.

What is audit logging in Node.js

Audit logging records important actions in your application.

For example, tracking when a user updates their email helps with security and debugging.

An audit log shows you who did what and when in your system. This can help with KYC, chargeback documentation, compliance stuff, and more.

Using Operational for Audit Logging

Operational is an open source event tracking tool.

You can use it to send audit log events from your Node.js app.

Operational Usage

Setting Up Operational

  1. Go to app.operational.co and sign up.
  2. Create a new project.
  3. Copy your API key from project settings.
  4. Store the key as an environment variable in your app.
  5. Install the Nodejs SDK for Operational
npm install --save @operational.co/sdk

Example Code

Pepper calls to the Operational SDK in your code.

Below are examples of tracking audit events in Node.js.

import Operational from '@operational.co/sdk'
const ops = new Operational(process.env.OPERATIONAL_API_KEY)

const payload = {
  name: 'User created',
  avatar: '📝',
  content: 'User John Smith created an account'
}

await ops.events.ingest(payload)
import Operational from '@operational.co/sdk'
const ops = new Operational(process.env.OPERATIONAL_API_KEY)

const payload = {
  name: 'Profile updated',
  avatar: '📝',
  content: 'User Jane Doe updated email from jane@old.com to jane@new.com'
}

await ops.events.ingest(payload)
import Operational from '@operational.co/sdk'
const ops = new Operational(process.env.OPERATIONAL_API_KEY)

const payload = {
  name: 'Permission changed',
  avatar: '📝',
  content: 'Admin Mark changed role of user Alice to moderator'
}

await ops.events.ingest(payload)
import Operational from '@operational.co/sdk'
const ops = new Operational(process.env.OPERATIONAL_API_KEY)

const payload = {
  name: 'File deleted',
  avatar: '📝',
  content: 'User Bob deleted report Q2_financials.pdf'
}

await ops.events.ingest(payload)

Each snippet shows how to send a different audit event to Operational.

Conclusion

Operational helps you build an audit log system with minimal setup.

You can track user and system actions in one place. You can also receive push notifications for these events right on your device too.

Learn more at https://operational.co and try out ready-to-paste code snippets in our playground.