Skip to content

dump() & dd()

dump()

Prints a formatted value to the terminal.

Syntax

ts
dump(value: unknown, options?: DumpOptions): unknown

Parameters

ParameterTypeDescription
valueunknownThe value to dump
optionsDumpOptionsConfiguration options (optional)

Return value

Returns the original value unchanged - enables chaining.

Options

OptionTypeDefaultDescription
view'flat' | 'tree' | 'table''flat'Visualisation style
depthnumber30Maximum nesting depth
colorsbooleanautotrue = force colors, false = no colors, auto = TTY-based
showHiddenbooleanfalseShow non-enumerable properties
maxArrayLengthnumber1000Maximum array items to display
maxStringLengthnumber5000Maximum string length
indentnumber2Spaces per indentation level
streamWriteStreamstderrOutput stream

Examples

Basic usage (flat view)

js
dump({ name: 'John', age: 30 });

Output:

{
  name: "John",
  age: 30
}

Tree view

js
const data = {
  name: 'John',
  address: {
    city: 'Lisbon',
    street: 'Augusta'
  }
};

dump(data, { view: 'tree' });

Output:

Object
├── name: "John"
└── address: Object
    ├── city: "Lisbon"
    └── street: "Augusta"

Table view (array of objects)

js
const users = [
  { name: 'Alice', age: 30, city: 'Lisbon' },
  { name: 'Bob', age: 25, city: 'Porto' }
];

dump(users, { view: 'table' });

Output:

name   | age | city
───────┼─────┼───────
Alice  | 30  | Lisbon
Bob    | 25  | Porto

With limited depth

js
const deep = { a: { b: { c: { d: 'deep' } } } };
dump(deep, { depth: 2 });

Output:

{
  a: {
    b: [Object]
  }
}

Without colors

js
dump({ error: 'Failed' }, { colors: false });

Output (no ANSI codes):

{
  error: "Failed"
}

Chaining

js
const result = dump(user).process();
// The value of user is printed, then process() is called

Custom stream

js
import { createWriteStream } from 'fs';
const stream = createWriteStream('./debug.log');
dump(data, { stream });
// Output is written to debug.log file

dd()

Dump and die - prints the value and terminates the process.

Syntax

ts
dd(value: unknown, options?: DumpOptions): never

Parameters

ParameterTypeDescription
valueunknownThe value to dump
optionsDumpOptionsConfiguration options (optional)

Return value

Never returns - calls process.exit(1).

Examples

Basic usage

js
function handler(req) {
  dd(req);
  // This code never runs
}

Output:

{
  method: "GET",
  url: "/api/users"
}

(Process terminates after output)

Conditional debugging

js
if (error) {
  dd({ error, context: 'api-failure' });
}

Differences between dump() and dd()

FunctionOutputContinues execution?
dump()Prints value✅ Yes
dd()Prints value❌ No (process.exit)

Tips

  • Use dump() to inspect values during normal flow
  • Use dd() to stop execution at a specific point
  • Use view: 'tree' to understand nested structures
  • Use view: 'table' for arrays of homogeneous objects
  • Chaining with dump() enables non-intrusive debugging:
js
const result = dump(process(data)).transform();
// The value of process(data) is shown, but transform() is still called

MIT License