NodeJs如何在控制台中显示结构化的表格

Hem*_*vrm 22 node.js

是否可以不安装新软件包?

在这里我使用 cli-table 包.. 在此处输入图片说明

有什么简单的方法可以做到吗?

sli*_*wp2 44

node.js 版本v10.16.0,你可以使用console.table API,而无需安装任何节点模块。

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);
Run Code Online (Sandbox Code Playgroud)

终端中的标准输出是这样的:

在此处输入图片说明

  • 是否可以删除第一个“索引”列? (10认同)
  • @Max我在这里找到了您的解决方案:/sf/answers/3755716191/ (2认同)

小智 5

var values = [];
Array.forEach(function(b, i) {
    values.push(
    {
        'Symbol': b.a,
        'BID': b.b,
        'CONVERT1': b.c,
        'Buy': b.d,
        'Sell': b.e,
        'Convert2': b.f
    });
});
console.table(values);
Run Code Online (Sandbox Code Playgroud)

结果控制台

结果控制台