npm package
boxen review
Use Boxen 9.0.0 for short, human-facing CLI summaries when your project meets its Node 22 requirement.
A boxed warning stops being useful when it runs past the edge of your terminal. Boxen creates boxes around terminal text. Version 9.0.0 supports a fixed width or a content-sized box capped by maxWidth. Pass a string and options, then print the returned string yourself. Titles, footers, spacing and border styles can help distinguish a short command summary from ordinary output. Boxen 9 requires Node.js 22 or newer.
Use Boxen 9.0.0 for short, human-facing CLI summaries when your project meets its Node 22 requirement. Begin with maxWidth, leave height unset for important messages, and keep a plain output path for pipes. Check the result on your supported terminals before relying on its layout.
Answers from our run
boxen or chalk: which should you use?
chalk: Chalk styles terminal strings. Consider it when styling is enough and you do not need a surrounding box. Its supplied npm description is 'Terminal string styling done right'. No Chalk integration example or runtime comparison was tested here. Use Boxen 9.0.0 for short, human-facing CLI summaries when your project meets its Node 22 requirement.
When should you not use boxen?
Your CLI must support Node 20 or older. Check an older Boxen major separately.
Use it if
Skip it if
Setup reality
Install the reviewed version with npm install boxen@9.0.0. Save an example as summary.mjs, use import boxen from 'boxen', and run node summary.mjs. The supplied npm manifest declares type: module, a default export at index.js, bundled declarations at index.d.ts, and Node >=22. An existing CommonJS project needs a separate module-loading decision. These examples use ESM throughout.
No installation, runtime examples, terminal rendering or performance tests were executed for this guide. The snippets are documentation-based illustrations checked against the supplied v9.0.0 README and implementation. The bundle contains no sandbox measurements.
Start with maxWidth and modest explicit padding. Setting width disables terminal overflow handling and can make a box look broken in a narrower terminal. maxWidth has no effect when width is set. A character wider than the remaining space can still widen the box because Boxen never splits a character. The implementation checks stdout columns, then stderr columns, then COLUMNS, and falls back to 80. Check redirected output separately from interactive output.
A numeric padding: 1 means one row above and below and three spaces on each side. Numeric margin uses the same horizontal multiplier. Use side objects for exact spacing. When horizontal padding would consume the available content width, the implementation clears it. Fixed height crops overflowing body text. Titles and footers can also be shortened to fit, so put essential instructions in the body and leave height unset. float places the box within terminal space; textAlignment aligns its contents.
The final example leaves redirected stdout plain and uses a classic border when stdout is a terminal. That branch is application policy. It does not make the plain message valid JSON or another structured format. Keep the words understandable without color.
The numeric scores are computed by the site's rubric. The accompanying notes explain the documentation supporting each category and its limits; they do not define the scoring scale or recalculate the scores. The supplied record does not include the published rubric's calculation. The notes draw on the declared API, README, release notes and implementation. They do not establish adoption, installation safety, runtime compatibility, performance or a future maintenance cadence.
Before using a boxed summary for important output, run it in your narrowest supported terminal and through a pipe. Those checks remain work for the integrating project.
Patterns
Print one short summary print-summary
import boxen from 'boxen';
const message = 'Build complete. Output: dist/';
const framed = boxen(message);
console.log(framed);Boxen returns formatted text. Printing is the caller's job. This documentation-based example was not executed.
Cap a content-sized box cap-width
import boxen from 'boxen';
console.log(boxen(
'Build complete. Check the generated files before deploying.',
{maxWidth: 44, padding: {left: 1, right: 1}},
));maxWidth limits growth without making short messages fill the width. Do not also set width. A character wider than its remaining space can still widen the box.
Reserve a fixed width when space is known set-width
import boxen from 'boxen';
console.log(boxen('Build complete.', {
width: 40,
padding: {left: 1, right: 1},
}));width includes the border and disables terminal overflow handling. Check the available terminal space before choosing it.
Set each spacing side explicitly control-spacing
import boxen from 'boxen';
console.log(boxen('Build complete.', {
padding: {top: 1, bottom: 1, left: 2, right: 2},
margin: {top: 1, bottom: 0, left: 0, right: 0},
}));Numeric padding and margin multiply horizontal spacing by three. Side objects avoid that multiplier. The implementation clears horizontal padding when it would consume the available content width.
Attach a title and footer label-summary
import boxen from 'boxen';
console.log(boxen('Output written to dist/. Review before deploy.', {
title: 'Build',
titleAlignment: 'left',
footer: 'Review before deploy',
footerAlignment: 'right',
maxWidth: 48,
}));Version 9.0.0 supports footer. Labels can be shortened to fit, so this illustration also places the instruction in the body. It was not executed.
Center text inside the box align-content
import boxen from 'boxen';
console.log(boxen('Build complete\nOutput: dist/', {
width: 36,
textAlignment: 'center',
}));textAlignment affects the contents. It does not center the box on the terminal. The fixed width still disables terminal overflow handling.
Center the box on the terminal place-box
import boxen from 'boxen';
console.log(boxen('Build complete.', {
float: 'center',
maxWidth: 40,
borderStyle: 'round',
}));float places the whole box in available terminal space. The function returns a formatted string; an application that needs updated output must call it again.
Give the title its own color color-title
import boxen from 'boxen';
console.log(boxen('Review the output before deploying.', {
title: 'Build finished',
borderColor: 'blue',
titleColor: 'yellow',
maxWidth: 50,
}));Version 9.0.0 supports titleColor. Styling already applied to the title takes precedence. Keep the message understandable without color.
Reserve rows for disposable status text reserve-height
import boxen from 'boxen';
console.log(boxen('Waiting for the next build.', {
height: 5,
maxWidth: 40,
}));With the default border, height includes the border rows. Fixed height crops overflowing body text. Use it only when losing extra status lines is acceptable.
Leave redirected stdout undecorated keep-pipes-plain
import process from 'node:process';
import boxen from 'boxen';
const message = 'Build complete. Output: dist/';
const output = process.stdout.isTTY
? boxen(message, {borderStyle: 'classic', maxWidth: 48})
: message;
console.log(output);The isTTY branch is application policy, not a Boxen feature. The plain branch is a text message; serialize the actual data if your CLI promises JSON. This illustration was not executed.
Alternatives
| Package | Registry | Pick it when |
|---|---|---|
| chalk | npm | Chalk styles terminal strings. Consider it when styling is enough and you do not need a surrounding box. Its supplied npm description is 'Terminal string styling done right'. No Chalk integration example or runtime comparison was tested here. |
| cli-boxes | npm | cli-boxes provides boxes for terminal use. Consider it when evaluating border components for a renderer you control. Its supplied npm description is 'Boxes for use in the terminal'; Boxen's implementation imports it for border styles. No standalone cli-boxes example was tested here. |
More cli & tooling guides
How this guide is made: grounded in the library's documentation, release notes, changelog, and issue history, on a fixed rubric — not a hands-on install of every release. The 50 most-downloaded entries are additionally install-verified in clean containers. Corrections: contact the desk.