ascii-table, cli-table, table, table-layout, and text-table are all npm packages designed to render tabular data in terminal environments. They convert structured data (arrays or objects) into human-readable, aligned text tables suitable for command-line interfaces, logging, debugging, or reporting. While they share the same core purpose, they differ significantly in API design, customization capabilities, input formats, visual styling, and maintenance status.
When building CLI tools, scripts, or server-side utilities that output structured data to the terminal, you need a reliable way to render tables. The npm ecosystem offers several mature options β ascii-table, cli-table, table, table-layout, and text-table β each with distinct design philosophies, feature sets, and trade-offs. Letβs compare them from an engineering perspective.
text-table is the minimalistβs choice β it focuses on one job: turning arrays into aligned text columns with minimal overhead.
const table = require('text-table');
const rows = [
['Name', 'Age', 'City'],
['Alice', 30, 'New York'],
['Bob', 25, 'San Francisco']
];
console.log(table(rows));
// Output:
// Name Age City
// Alice 30 New York
// Bob 25 San Francisco
ascii-table provides a fluent API with built-in header support and alignment control, but uses a more object-oriented style.
const AsciiTable = require('ascii-table');
const table = new AsciiTable('People');
table
.setHeading('Name', 'Age', 'City')
.addRow('Alice', 30, 'New York')
.addRow('Bob', 25, 'San Francisco');
console.log(table.toString());
cli-table (and its successor cli-table3) emphasizes visual styling with customizable borders using box-drawing characters.
const Table = require('cli-table');
const table = new Table({
head: ['Name', 'Age', 'City'],
colWidths: [10, 5, 15]
});
table.push(
['Alice', 30, 'New York'],
['Bob', 25, 'San Francisco']
);
console.log(table.toString());
table takes a configuration-first approach, offering extensive control over layout, alignment, padding, and cell formatting via a single table() function and options object.
const { table } = require('table');
const data = [
['Name', 'Age', 'City'],
['Alice', 30, 'New York'],
['Bob', 25, 'San Francisco']
];
const config = {
columns: {
1: { alignment: 'right' }
}
};
console.log(table(data, config));
table-layout treats table rendering as a layout problem, supporting streaming output and dynamic column sizing based on content.
const Table = require('table-layout');
const rows = [
{ name: 'Alice', age: 30, city: 'New York' },
{ name: 'Bob', age: 25, city: 'San Francisco' }
];
const t = new Table(rows, {
columns: [
{ key: 'name', width: 10 },
{ key: 'age', width: 5, align: 'right' },
{ key: 'city', width: 15 }
]
});
console.log(t.toString());
If your tool needs polished output for user-facing CLIs (e.g., deployment reports, analytics dashboards), visual fidelity matters.
cli-table excels here with full border control using Unicode box-drawing characters. You can customize vertical/horizontal separators, corner glyphs, and even colors (via ANSI codes).const Table = require('cli-table');
const table = new Table({
chars: {
'top': 'β', 'top-mid': 'β€', 'top-left': 'β', 'top-right': 'β',
'bottom': 'β', 'bottom-mid': 'β§', 'bottom-left': 'β', 'bottom-right': 'β',
'left': 'β', 'left-mid': 'β', 'mid': 'β', 'mid-mid': 'βΌ',
'right': 'β', 'right-mid': 'β’'
},
head: ['Feature', 'Status'],
colWidths: [15, 10]
});
table.push(['CLI Output', 'β
']);
console.log(table.toString());
table supports custom draw functions for borders and cells, allowing fine-grained control over every character used in the grid.const { table } = require('table');
const data = [['A', 'B'], ['1', '2']];
const config = {
border: {
topBody: `β`,
topJoin: `β¬`,
topLeft: `β`,
topRight: `β`,
// ... other border parts
}
};
console.log(table(data, config));
text-table, ascii-table, and table-layout offer little to no border customization. ascii-table uses basic ASCII (+, -, |), while text-table outputs plain space-aligned columns with no borders at all.β οΈ Note: The original
cli-tablepackage is deprecated. Its GitHub repository (Automattic/cli-table) states: βThis package is no longer maintained. Please use cli-table3 instead.β However, since the prompt specifiescli-table(notcli-table3), we treat it as legacy and advise against using it in new projects.
How you structure your data affects which library integrates smoothly into your codebase.
text-table and table accept a simple 2D array (string[][]). This works well with CSV-like or matrix data.
ascii-table requires method chaining (addRow(), setHeading()), which is less functional and harder to compose.
table-layout uniquely accepts an array of objects ({ key: value }[]), making it ideal when working with JSON APIs or database query results.
cli-table uses a mix: headers via head option, rows via .push().
If your data comes from JSON.parse() or an ORM query, table-layoutβs object-based input avoids manual mapping:
// With table-layout
const users = await db.query('SELECT name, email FROM users');
const t = new Table(users); // No transformation needed
// With table
const data = [ ['Name', 'Email'], ...users.map(u => [u.name, u.email]) ];
For professional-grade output, you often need per-column alignment, padding control, or content truncation.
table provides the most comprehensive options:const { table } = require('table');
const data = [['Left', 'Center', 'Right'], ['A', 'B', 'C']];
const config = {
columns: {
0: { alignment: 'left', paddingLeft: 1, paddingRight: 2 },
1: { alignment: 'center' },
2: { alignment: 'right', truncate: 5 }
}
};
console.log(table(data, config));
table-layout supports align (left/right/center) and width per column, plus automatic word wrapping.
ascii-table allows setting alignment per column via .align():
const table = new AsciiTable();
table.setHeading('Name', 'Score');
table.align(1, AsciiTable.RIGHT); // align second column right
table.addRow('Alice', 98);
text-table supports global alignment via options, but not per-column:const opts = { align: ['l', 'r'] }; // left, right
console.log(table([['A', '1']], opts));
cli-table does not support text alignment within cells β all content is left-aligned by default.As verified via npm and GitHub:
cli-table is officially deprecated. The npm page links to cli-table3 as the successor. Do not use cli-table in new projects.ascii-table, text-table, table, and table-layout are not marked as deprecated and have recent commits or releases.However, note that ascii-table hasnβt seen significant updates in years, though it remains stable for basic use cases.
Youβre writing a quick script to inspect database records during development.
text-tableconst tt = require('text-table');
console.log(tt([['ID', 'Status'], ...records.map(r => [r.id, r.status])]));
Your CLI shows formatted reports with borders, colors, and clean alignment (e.g., git-style output).
tableYouβre processing log files and want to stream formatted rows without buffering everything in memory.
table-layout.write() and .end(), and handles dynamic column widths.Youβre maintaining an old project already using ascii-table.
ascii-table if output requirements are simple.You want modern, actively maintained tooling.
cli-table β use cli-table3 if you need its style, but note it wasnβt in the comparison list.table or table-layout for future-proofing.| Feature | ascii-table | cli-table | table | table-layout | text-table |
|---|---|---|---|---|---|
| Input Format | Method chaining | Array + .push() | string[][] | { key: val }[] | string[][] |
| Borders | Basic ASCII | Unicode (custom) | Fully customizable | None | None |
| Per-Column Align | β | β | β | β | β (global only) |
| Padding Control | β | β | β | Via width | β |
| Streaming Support | β | β | β | β | β |
| Maintenance Status | Stable (inactive) | β Deprecated | β Active | β Active | β Stable |
table.table-layout.text-table.cli-table due to deprecation.ascii-table if youβre already invested in its API or need its specific output style.In professional frontend or full-stack tooling β where maintainability, clarity, and robustness matter β table strikes the best balance between power, simplicity, and active maintenance.
Choose ascii-table if you prefer a fluent, object-oriented API with method chaining (addRow, setHeading) and need basic ASCII table output with per-column alignment. Itβs suitable for simple internal scripts where visual polish isnβt critical, but avoid it for new projects requiring advanced layout control or active maintenance.
Do NOT choose cli-table for new projects β it is officially deprecated according to its npm and GitHub pages. If you encounter it in legacy code, plan to migrate to cli-table3 or another alternative. Its Unicode border styling was once compelling, but unmaintained dependencies pose long-term risks.
Choose table when you need maximum control over table appearance β including custom borders, per-column alignment, padding, truncation, and draw functions β with a clean, functional API based on 2D arrays and configuration objects. Itβs ideal for professional CLI tools requiring polished, consistent output and active maintenance.
Choose table-layout if your data is structured as an array of objects (e.g., from JSON APIs or database queries) and you need streaming support, dynamic column sizing, or automatic word wrapping. Its object-oriented column definitions make it ergonomic for data-heavy CLI applications that process large datasets incrementally.
Choose text-table for minimal, zero-config table rendering in debug scripts or internal tools where simplicity and small footprint matter more than borders or advanced formatting. It aligns columns cleanly using spaces but offers no visual framing or per-column customization.
Easy table output for node debugging, but you could probably do more with it, since its just a string.
Node.js
var AsciiTable = require('ascii-table')
Browser
<script src="ascii-table.min.js"></script>
Note: If using in the browser, it will be placed under window.AsciiTable
Basic usage
var table = new AsciiTable('A Title')
table
.setHeading('', 'Name', 'Age')
.addRow(1, 'Bob', 52)
.addRow(2, 'John', 34)
.addRow(3, 'Jim', 83)
console.log(table.toString())
.----------------.
| A Title |
|----------------|
| | Name | Age |
|---|------|-----|
| 1 | Bob | 52 |
| 2 | John | 34 |
| 3 | Jim | 83 |
'----------------'
We can make a simple table without a title or headings as well.
var table = new AsciiTable()
table
.addRow('a', 'apple', 'Some longer string')
.addRow('b', 'banana', 'hi')
.addRow('c', 'carrot', 'meow')
.addRow('e', 'elephants')
console.log(table.toString())
.------------------------------------.
| a | apple | Some longer string |
| b | banana | hi |
| c | carrot | meow |
| e | elephants | |
'------------------------------------'
See: AsciiTable.factory for details on instantiation
Table instance creator
title - table title (optional, default null)options - table options (optional)
prefix - string prefix to add to each line on renderNote: If an object is passed in place of the title, the fromJSON
method will be used to populate the table.
Example:
var table = AsciiTable.factory('title')
var table = AsciiTable.factory({
title: 'Title'
, heading: [ 'id', 'name' ]
, rows: [
[ 1, 'Bob' ]
, [ 2, 'Steve' ]
]
})
Shortcut to one of the three following methods
direction - alignment direction (AsciiTable.LEFT, AsciiTable.CENTER, AsciiTable.RIGHT)val - string to alignlen - total length of created stringpad - padding / fill char (optional, default ' ')Example:
table.align(AsciiTable.LEFT, 'hey', 7) // 'hey '
val - string to alignlen - total length of created stringpad - padding / fill char (optional, default ' ')Example:
table.alignLeft('hey', 7, '-') // 'hey----'
val - string to alignlen - total length of created stringpad - padding / fill char (optional, default ' ')Example:
table.alignCenter('hey', 7) // ' hey '
val - string to alignlen - total length of created stringpad - padding / fill char (optional, default ' ')Example:
table.alignRight('hey', 7) // ' hey'
Attempt to do intelligent alignment of provided val, String input will
be left aligned, Number types will be right aligned.
val - string to alignlen - total length of created stringpad - padding / fill char (optional, default ' ')Example:
table.align(AsciiTable.LEFT, 'hey', 7) // 'hey '
Create a new array at the given len, filled with the given value, mainly used internally
len - length of arrayval - fill value (optional)Example:
AsciiTable.arrayFill(4, 0) // [0, 0, 0, 0]
Set the border characters for rendering, if no arguments are passed it will be
reset to defaults. If a single edge arg is passed, it will be used for all borders.
edge - horizontal edges (optional, default |)fill - vertical edges (optional, default -)top - top corners (optional, default .)bottom - bottom corners (optional, default ')Example:
var table = new AsciiTable('Stars')
table
.setBorder('*')
.setHeading('oh', 'look')
.addRow('so much', 'star power')
console.log(table.toString())
************************
* Stars *
************************
* oh * look *
************************
* so much * star power *
************************
Example:
table.removeBorder()
console.log('' + table)
# Fruit Thing
--- ----------- --------------------
a apple Some longer string
b banana hi
c carrot meow
e elephants
idx - column index to aligndirection - alignment direction, (AsciiTable.LEFT, AsciiTable.CENTER, AsciiTable.RIGHT)Example:
table
.setAlign(2, AsciiTable.RIGHT)
.setAlign(1, AsciiTable.CENTER)
console.log(table.toString())
.-------------------------------------.
| a | apple | Some longer string |
| b | banana | hi |
| c | carrot | meow |
| e | elephants | |
'-------------------------------------'
Alias to instance.setAlign(idx, AsciiTable.LEFT)
Alias to instance.setAlign(idx, AsciiTable.CENTER)
Alias to instance.setAlign(idx, AsciiTable.RIGHT)
title - table titleExample:
var table = new AsciiTable('Old Title')
table.setTitle('New Title')
Get the current title of the table
Example:
table.getTitle() // 'New Title'
direction - table alignment directionExample:
Alias to instance.setTitleAlign(AsciiTable.LEFT)
Alias to instance.setTitleAlign(AsciiTable.CENTER)
Alias to instance.setTitleAlign(AsciiTable.RIGHT)
iterator - sorting method to run against the rowsExample:
table.sort(function(a, b) {
return a[2] - b[2]
})
console.log(table.toString())
.----------------.
| 2 | John | 34 |
| 1 | Bob | 52 |
| 3 | Jim | 83 |
'----------------'
Sorting shortcut for targeting a specific column
index - column idx to sortiterator - sorting method to run against column valuesExample:
// This is quivalent to the `sort` example above
table.sortColumn(2, function(a, b) {
return a - b
})
Set the column headings for the table, takes arguments the same way as addRow
heading - heading array or argumentsExample:
table.setHeading('ID', 'Key', 'Value')
// or:
table.setHeading(['ID', 'Key', 'Value'])
direction -Example:
Alias to instance.setHeadingAlignLeft(AsciiTable.LEFT)
Alias to instance.setHeadingAlignLeft(AsciiTable.CENTER)
Alias to instance.setHeadingAlignLeft(AsciiTable.RIGHT)
Rows can be added using a single array argument, or the arguments if multiple args are used when calling the method.
row - array or arguments of column valuesExample:
var table = new AsciiTable()
table
.addRow(1, 'Bob', 52)
.addRow([2, 'John', 34])
console.log(table.render())
.---------------.
| 1 | Bob | 52 |
| 2 | John | 34 |
'---------------'
Bulk addRow operation
rows - multidimentional array of rowsExample:
table.addRowMatrix([
[2, 'John', 34]
, [3, 'Jim', 83]
])
Justify all columns to be the same width
enabled - boolean for turning justify on or off, undefined considered trueExample:
table
.addRow('1', 'two', 'three')
.setJustify()
console.log(table.toString())
.-----------------------.
| 1 | two | three |
'-----------------------'
Render the instance as a string for output
Alias: [valueOf, render]
Return the JSON representation of the table, this also allows us to call
JSON.stringify on the instance.
Example:
var table = new AsciiTable('Title')
table
.setHeading('id', 'name')
.addRow(1, 'Bob')
.addRow(2, 'Steve')
console.log(table.toJSON())
console.log(JSON.stringify(table))
{
title: 'Title'
, heading: [ 'id', 'name' ]
, rows: [
[ 1, 'Bob' ]
, [ 2, 'Steve' ]
]
}
{"title":"Title","heading":["id","name"],"rows":[[1,"Bob"],[2,"Steve"]]}
Populate the table from json object, should match the toJSON output above.
Alias: [parse]
Example:
var table = new AsciiTable().fromJSON({
title: 'Title'
, heading: [ 'id', 'name' ]
, rows: [
[ 1, 'Bob' ]
, [ 2, 'Steve' ]
]
})
Clear / reset all table data
Alias: [reset]
Reset all row data, maintains title and headings.
With npm
npm install ascii-table
(The MIT License)
Copyright (c) 2013 Beau Sorensen
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.