View env vars on your server in JavaScript

Learn how to view environment variables on your JavaScript server and log their values with Operational for easier debugging.

Why view environment variables on your server?

Server environment variables hold critical config and secrets outside your code.

Viewing them can help you debug misconfigurations and verify values.

For example, you might check that DB_URL matches your database in development.

Logging environment variable events with Operational

Operational is an open source event tracking tool for your apps.

You can use it to log when you read or change env vars on your server.

Operational in action

Setting up Operational

  1. Go to app.operational.co and create an account.
  2. Copy your API key from the dashboard.
  3. Install the SDK with npm or yarn.
  4. Initialize Operational in your project using the API key.

Code example

import Operational from "@operational.co/sdk"

const ops = new Operational("YOUR_API_KEY")

const dbUrl = process.env.DB_URL

const payload = {
  name: "Environment variable accessed",
  avatar: "🔑",
  content: `The DB_URL environment variable is ${dbUrl}`
}

await ops.events.ingest(payload)

This snippet logs an event when you read the DB_URL environment variable.

Conclusion

Tracking environment variable access can save time debugging and reveal config issues.

Operational makes it easy to log these events and view them in one dashboard.

Learn more at https://operational.co

Try snippets in the playground.