# @aidra/pmx-io

In-process instrumentation for Node.js and Bun apps that report to
[prodman](https://github.com/westonpark/prodman): metrics, custom actions, exceptions, events,
logs, CPU and heap profiling, and distributed tracing with database and message-broker
integrations. It keeps the `@pm2/io` API, so code written for PM2.io works unchanged.

* **Run by pmx:** pmx injects this library into every app it starts; nothing to install. An
  installed copy stays idle and `require` returns the injected instance.
* **Run by PM2 / pm2_prodman:** reports through the PM2 daemon, like `@pm2/io`.
* **Standalone** (a container's `node app.js`, an ECS task, a worker): connects to prodman
  itself as a one-process agent.

Node.js 18 or later, or Bun 1.1 or later. No dependencies.

## Install

```sh
npm install @aidra/pmx-io
```

Code that requires `@pm2/io` can keep doing so: install the package under that name.

```sh
npm install @pm2/io@npm:@aidra/pmx-io
```

## Standalone mode

Set the bucket keys (prodman: *Bucket settings → Connect servers*) and an app name:

```sh
PRODMAN_URL=https://prodman.example.com
PM2_PUBLIC_KEY=<public key>
PM2_SECRET_KEY=<secret key>
PM2_APP_NAME=orders-api
```

Then load the library without changing code:

```sh
npx pmx-io-node run -- node server.js
node --require @aidra/pmx-io/standalone server.js
NODE_OPTIONS='--import @aidra/pmx-io/standalone.mjs' node server.mjs
```

or require it first thing in the app:

```js
const io = require('@aidra/pmx-io')
io.init({ apmOptions: { sendLogs: true, application: 'shop' } })
```

Settings, server names, containers and troubleshooting: prodman's documentation page
*Node.js apps without pmx* (`/docs/node-apm`).

## API

```js
const io = require('@aidra/pmx-io')

io.metric({ name: 'Queue length' }).set(12)
io.counter({ name: 'Jobs done' }).inc()
io.action('flush cache', (reply) => reply({ ok: true }))
io.notifyError(new Error('payment failed'), { custom: { orderId } })
```

TypeScript declarations are included (`index.d.ts`), a superset of `@pm2/io`'s.

Proprietary. © 2026 Mike Warriner.
