NodeJs how to display table structured in console

前端 未结 3 1292
温柔的废话
温柔的废话 2021-02-07 10:38

Is it possible without installing new package?

Here i am using cli-table package..

Any easy way to do it ?

相关标签:
3条回答
  • 2021-02-07 10:56

    I love this package for updating texts on the terminal instead of adding new lines : https://github.com/ivanseidel/node-draftlog

    0 讨论(0)
  • 2021-02-07 10:57
    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);
    

    Result Console

    0 讨论(0)
  • 2021-02-07 11:02

    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:

    0 讨论(0)
提交回复
热议问题