TIL: console.table in Node.js (from the archives)
tilnodejsjavascript
Today I learned that console.table is a thing in Node.js. I'd seen it used in browser dev tools before, but never thought to reach for it in a Node script. Turns out it works great for debugging or formatting simple script output.
What it does
console.table takes an array or object and renders it as a nicely formatted table right in your terminal. For example:
const users = [
{ name: "Alice", role: "admin" },
{ name: "Bob", role: "editor" },
{ name: "Carol", role: "viewer" },
];
console.table(users);This prints a proper table with columns and rows instead of the usual nested object dump you get from console.log. Much easier to scan when you're working with structured data.
When it's useful
- Debugging arrays of objects (API responses, database rows, etc.)
- Quick-and-dirty output formatting for CLI scripts
- Comparing properties across a set of items at a glance
You can also pass a second argument to select which columns to display:
console.table(users, ["name"]);Check out the MDN docs for the full API.