# pino-std-serializers

> A collection of standard object serializers for Pino

Latest version **7.1.0** (published 2026-01-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install pino-std-serializers
pnpm add pino-std-serializers
yarn add pino-std-serializers
bun add pino-std-serializers
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 7.1.0 |
| Published | 2026-01-13 |
| First published | 2018-02-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 52.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 76 |
| Author | James Sumners |
| Maintainers | matteo.collina, jsumners, watson |
| Keywords | pino, logging |

## Links

- npm: https://www.npmjs.com/package/pino-std-serializers
- Repository: https://github.com/pinojs/pino-std-serializers
- Homepage: https://github.com/pinojs/pino-std-serializers#readme
- Issues: https://github.com/pinojs/pino-std-serializers/issues
- npm.io page: https://npm.io/package/pino-std-serializers

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 7.1.0 (latest) — 2026-01-13
- 7.0.0 — 2024-04-29
- 6.2.2 — 2023-06-25
- 6.2.1 — 2023-05-03
- 6.2.0 — 2023-04-09
- 6.1.0 — 2022-12-27
- 6.0.0 — 2022-06-20
- 5.6.0 — 2022-06-13
- 5.5.0 — 2022-06-10
- 5.4.0 — 2022-06-10
- 5.3.0 — 2022-05-24
- 5.2.0 — 2022-04-05
- 5.1.1 — 2022-02-23
- 5.1.0 — 2022-01-19
- 5.0.0 — 2021-11-24
- … 18 more at https://npm.io/package/pino-std-serializers/versions

## README

# pino-std-serializers&nbsp;&nbsp;[![CI](https://github.com/pinojs/pino-std-serializers/workflows/CI/badge.svg)](https://github.com/pinojs/pino-std-serializers/actions?query=workflow%3ACI)

This module provides a set of standard object serializers for the
[Pino](https://getpino.io) logger.

## Serializers

### `exports.err(error)`
Serializes an `Error` like object. Returns an object:

```js
{
  type: 'string', // The name of the object's constructor.
  message: 'string', // The supplied error message.
  stack: 'string', // The stack when the error was generated.
  raw: Error  // Non-enumerable, i.e. will not be in the output, original
              // Error object. This is available for subsequent serializers
              // to use.
  [...any additional Enumerable property the original Error had]
}
```

Any other extra properties, e.g. `statusCode`, that have been attached to the
object will also be present on the serialized object.

If the error object has a [`cause`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause) property, the `cause`'s `message` and `stack` will be appended to the top-level `message` and `stack`. All other parameters that belong to the `error.cause` object will be omitted.

Example:

```js
const serializer = require('pino-std-serializers').err;

const innerError = new Error("inner error");
innerError.isInner = true;
const outerError = new Error("outer error", { cause: innerError });
outerError.isInner = false;

const serialized = serializer(outerError);
/* Result:
{
  "type": "Error",
  "message": "outer error: inner error",
  "isInner": false,
  "stack": "Error: outer error
        at <...omitted..>
    caused by: Error: inner error
        at <...omitted..>
}
 */
```

### `exports.errWithCause(error)`
Serializes an `Error` like object, including any `error.cause`. Returns an object:

```js
{
  type: 'string', // The name of the object's constructor.
  message: 'string', // The supplied error message.
  stack: 'string', // The stack when the error was generated.
  cause?: Error, // If the original error had an error.cause, it will be serialized here
  raw: Error  // Non-enumerable, i.e. will not be in the output, original
              // Error object. This is available for subsequent serializers
              // to use.
  [...any additional Enumerable property the original Error had]
}
```

Any other extra properties, e.g. `statusCode`, that have been attached to the object will also be present on the serialized object.

Example:
```javascript
const serializer = require('pino-std-serializers').errWithCause;

const innerError = new Error("inner error");
innerError.isInner = true;
const outerError = new Error("outer error", { cause: innerError });
outerError.isInner = false;

const serialized = serializer(outerError);
/* Result:
{
  "type": "Error",
  "message": "outer error",
  "isInner": false,
  "stack": "Error: outer error
    at <...omitted..>",
  "cause": {
    "type": "Error",
    "message": "inner error",
    "isInner": true,
    "stack": "Error: inner error
      at <...omitted..>"
  },
}
 */
```

### `exports.mapHttpResponse(response)`
Used internally by Pino for general response logging. Returns an object:

```js
{
  res: {}
}
```

Where `res` is the `response` as serialized by the standard response serializer.

### `exports.mapHttpRequest(request)`
Used internall by Pino for general request logging. Returns an object:

```js
{
  req: {}
}
```

Where `req` is the `request` as serialized by the standard request serializer.

### `exports.req(request)`
The default `request` serializer. Supports both Node.js `IncomingMessage` and WHATWG Fetch API `Request` objects. Returns an object:

```js
{
  id: 'string', // Defaults to `undefined`, unless there is an `id` property
                // already attached to the `request` object or to the `request.info`
                // object. Attach a synchronous function
                // to the `request.id` that returns an identifier to have
                // the value filled.
  method: 'string',
  url: 'string', // the request pathname (as per req.url in core HTTP)
                 // or full URL for WHATWG Request
  query: 'object', // the request query (as per req.query in express or hapi)
  params: 'object', // the request params (as per req.params in express or hapi)
  headers: Object, // a reference to the `headers` object from the request
                   // (as per req.headers in core HTTP)
  remoteAddress: 'string',
  remotePort: Number,
  raw: Object // Non-enumerable, i.e. will not be in the output, original
              // request object. This is available for subsequent serializers
              // to use. In cases where the `request` input already has
              // a `raw` property this will replace the original `request.raw`
              // property
}
```

### `exports.res(response)`
The default `response` serializer. Supports both Node.js `ServerResponse` and WHATWG Fetch API `Response` objects. Returns an object:

```js
{
  statusCode: Number, // Response status code, will be null before headers are flushed
                      // (Node.js only)
  headers: Object, // The headers to be sent in the response.
  raw: Object // Non-enumerable, i.e. will not be in the output, original
              // response object. This is available for subsequent serializers
              // to use.
}
```

### `exports.nodeReq(request)`
Serializes a Node.js `IncomingMessage` request object. Use this if you know the request is always a Node.js request. Returns the same shape as `exports.req()`.

### `exports.nodeRes(response)`
Serializes a Node.js `ServerResponse` object. Use this if you know the response is always a Node.js response. Returns the same shape as `exports.res()`.

### `exports.whatwgReq(request)`
Serializes a WHATWG Fetch API `Request` object. Use this for frameworks like Hono, Next.js App Router, SvelteKit, Remix, and others that use the Fetch API. Returns the same shape as `exports.req()`.

### `exports.whatwgRes(response)`
Serializes a WHATWG Fetch API `Response` object. Use this for frameworks that use the Fetch API. Returns the same shape as `exports.res()`.

### `exports.wrapErrorSerializer(customSerializer)`
A utility method for wrapping the default error serializer. This allows
custom serializers to work with the already serialized object.

The `customSerializer` accepts one parameter — the newly serialized error
object — and returns the new (or updated) error object.

### `exports.wrapRequestSerializer(customSerializer)`
A utility method for wrapping the default request serializer. This allows
custom serializers to work with the already serialized object.

The `customSerializer` accepts one parameter — the newly serialized request
object — and returns the new (or updated) request object.

### `exports.wrapResponseSerializer(customSerializer)`
A utility method for wrapping the default response serializer. This allows
custom serializers to work with the already serialized object.

The `customSerializer` accepts one parameter — the newly serialized response
object — and returns the new (or updated) response object.

## License

MIT License

---
_Source: https://npm.io/package/pino-std-serializers · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
