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.
Setting Up Operational
- Go to app.operational.co and sign up.
- Create a new project.
- Copy your API key from project settings.
- Store the key as an environment variable in your app.
- 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.