{"id":16788,"library":"cli-table","title":"CLI Table Generator","description":"cli-table is a Node.js utility for rendering structured, unicode-aided tables directly in the command line interface. As of its latest version 0.3.11, last published approximately four years ago, it provides extensive customization options including configurable characters for borders, adjustable column widths, text truncation, alignment (left, right, center), and padding. It also supports styling table headers through integration with the `colors.js` library. While its version number (0.3.x) and infrequent updates suggest it's a stable but not actively developed project, it remains a popular choice for producing visually organized output in CLI applications, evidenced by over 2.6 million weekly downloads. Its primary differentiator is its granular control over table aesthetics, allowing developers to create highly tailored visual presentations beyond simple CSV-like output.","status":"maintenance","version":"0.3.11","language":"javascript","source_language":"en","source_url":"https://github.com/Automattic/cli-table","tags":["javascript","cli","colors","table"],"install":[{"cmd":"npm install cli-table","lang":"bash","label":"npm"},{"cmd":"yarn add cli-table","lang":"bash","label":"yarn"},{"cmd":"pnpm add cli-table","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for color/background styling in table headers.","package":"colors","optional":false}],"imports":[{"note":"cli-table is a CommonJS module. Direct ES module import will fail in environments not explicitly configured for CJS-ESM interop.","wrong":"import Table from 'cli-table';","symbol":"Table","correct":"const Table = require('cli-table');"},{"note":"The primary export is a constructor function used to instantiate a table with configuration options.","symbol":"Table (configured)","correct":"const Table = require('cli-table');\nconst table = new Table({\n  head: ['Header 1', 'Header 2'],\n  colWidths: [20, 40]\n});"},{"note":"Rows can be initialized directly in the constructor for smaller tables.","symbol":"Table (rows init)","correct":"const Table = require('cli-table');\nconst table = new Table({\n  rows: [\n      ['Row 1 Col 1', 'Row 1 Col 2'],\n      ['Row 2 Col 1', 'Row 2 Col 2']\n  ]\n});"}],"quickstart":{"code":"const Table = require('cli-table');\n\n// Instantiate a new table with custom headers and column widths\nconst table = new Table({\n    head: ['Task ID', 'Description', 'Status', 'Due Date']\n  , colWidths: [10, 40, 15, 20] // Define column widths\n  , chars: {\n        'top': '═' , 'top-mid': '╤' , 'top-left': '╔' , 'top-right': '╗'\n      , 'bottom': '═' , 'bottom-mid': '╧' , 'bottom-left': '╚' , 'bottom-right': '╝'\n      , 'left': '║' , 'left-mid': '╟' , 'mid': '─' , 'mid-mid': '┼'\n      , 'right': '║' , 'right-mid': '╢' , 'middle': '│'\n    }\n});\n\n// Add rows to the table. Table is an Array-like object.\ntable.push(\n    [1, 'Implement feature A', 'In Progress', '2026-05-01']\n  , [2, 'Fix bug in module B that causes a critical error', 'Blocked', '2026-04-28']\n  , [3, 'Review pull request #123', 'Pending', '2026-04-25']\n);\n\n// Log the table to the console\nconsole.log(table.toString());\n\n// Example of a vertical table\nconst verticalTable = new Table();\nverticalTable.push(\n    { 'User': 'Alice' }\n  , { 'Role': 'Admin' }\n  , { 'Last Login': '2026-04-22 10:30' }\n);\nconsole.log('\\nVertical Table:');\nconsole.log(verticalTable.toString());","lang":"javascript","description":"This quickstart demonstrates how to create both a horizontal and a vertical unicode table with custom headers, column widths, and character styles, then populate and print them to the console."},"warnings":[{"fix":"Use `const Table = require('cli-table');` for importing in CommonJS modules. For ES modules, consider a package like `cli-table3` which offers better ESM compatibility, or configure Node.js `type: module` and potentially use dynamic `import('cli-table')`.","message":"The `cli-table` package (version 0.3.11) is a CommonJS module. Direct `import` statements in ES module contexts will result in `ERR_REQUIRE_ESM` errors unless specific Node.js loader configurations or transpilation are used.","severity":"gotcha","affected_versions":">=0.3.0"},{"fix":"Ensure `colors.js` is pinned to a known stable version in your `package-lock.json` or `yarn.lock`. Consider using `npm audit` or `snyk test` to check for known vulnerabilities in your dependency tree. If using `cli-table3` (a maintained fork), it uses `@colors/colors` which is a more stable alternative.","message":"The `colors.js` dependency, while functional in the version `cli-table` uses, was subject to a highly publicized supply chain attack (self-sabotage) in January 2022. While `cli-table` itself wasn't directly compromised, transitive dependency resolution could theoretically pull in a problematic version if not carefully managed, or if `colors.js` has further incidents.","severity":"gotcha","affected_versions":">=0.3.0"},{"fix":"Thoroughly test custom `chars` configurations with various data lengths and content. Refer to the documentation's examples for correct unicode character usage. Start with a simpler `chars` object and gradually add complexity.","message":"Configuring the `chars` property for custom table borders can be verbose and error-prone. Small mistakes in character assignment or omission can lead to malformed or visually broken table layouts.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Strip ANSI color codes from cell content before passing it to `cli-table` for column width calculation, then reapply them before `toString()`. Or, consider using `cli-table3`, which has more robust truncation and wrapping for ANSI colored text.","message":"Text containing ANSI color codes (e.g., from `chalk` or `colors.js` when applied to cell content) can cause `colWidths` calculations to be inaccurate, leading to misaligned columns or unexpected truncation. The invisible control characters are counted in length, but not rendered visibly.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"For new projects or if you require ongoing maintenance and new features, migrate to `cli-table3` (`npm install cli-table3`). For existing projects using `cli-table`, be aware of the lack of updates and potential for unpatched issues.","message":"The package `cli-table` has not seen new versions released to npm in the past 12 months (as of early 2026) and can be considered a discontinued project with low attention from maintainers. For active development and new features, consider `cli-table3`, which is an actively maintained, API-compatible fork.","severity":"gotcha","affected_versions":">=0.3.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Change the import statement to `const Table = require('cli-table');`.","cause":"Attempting to use `import Table from 'cli-table'` in a Node.js environment where `cli-table` is detected as a CommonJS module and `import` is not correctly transpiled or configured for interop.","error":"TypeError: Table is not a constructor"},{"fix":"Verify `colWidths` are sufficient for the content. If using ANSI colors, ensure they are handled correctly (e.g., stripped for length calculation). Double-check the `chars` object for correct unicode characters and complete definitions. Consider `cli-table3` for improved ANSI color handling.","cause":"This often occurs due to incorrect `colWidths` being set, especially when column content includes invisible ANSI color codes or when `chars` configuration is malformed.","error":"Table rows appear broken, misaligned, or text is unexpectedly truncated."},{"fix":"Always call `console.log(table.toString());` or assign `table.toString()` to a variable.","cause":"Forgetting to call `.toString()` on the `cli-table` instance before attempting to log or manipulate its string representation. The `table` object itself is not a string.","error":"`Cannot read property 'toString' of undefined` or `undefined is not a function (near '...table.toString()...')`"}],"ecosystem":"npm","meta_description":null}