Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJs how to display table structured in console

Tags:

Is it possible without installing new package?

Here i am using cli-table package.. enter image description here

Any easy way to do it ?

like image 890
Hemanthvrm Avatar asked Nov 10 '17 17:11

Hemanthvrm


People also ask

What console method will you call to see array data in a table?

The console. table() method displays tabular data as a table. This function takes one mandatory argument data , which must be an array or an object, and one additional optional parameter columns .

How do I use console commands in node JS?

console.log([data][, ... Prints to stdout with newline. This function can take multiple arguments in a printf()-like way.


1 Answers

node.js version v10.16.0, you can use console.table API without installing any node module.

const structDatas = [     { handler: 'http', endpoint: 'http://localhost:3000/path', method: 'ALL' },     { handler: 'event', endpoint: 'http://localhost:3000/event', method: 'POST' },     { handler: 'GCS', endpoint: 'http://localhost:3000/GCS', method: 'POST' } ]; console.table(structDatas); 

The stdout in terminal like this:

enter image description here

like image 80
slideshowp2 Avatar answered Sep 18 '22 14:09

slideshowp2