Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将console.log中的sql输出打印成包含行和列的html_Html_Node.js_Npm - Fatal编程技术网

如何将console.log中的sql输出打印成包含行和列的html

如何将console.log中的sql输出打印成包含行和列的html,html,node.js,npm,Html,Node.js,Npm,下面是我的HTML示例代码,我必须以正确的表格格式打印数据 redshiftClient.query('SELECT top 10 * FROM table') .then(function (data) { console.log(data); var mail = { from: '******@outlook.com', to: '******@test.co.in', subj

下面是我的HTML示例代码,我必须以正确的表格格式打印数据

redshiftClient.query('SELECT top 10 * FROM table')
    .then(function (data) {
        console.log(data);
        var mail = {
            from: '******@outlook.com',
            to: '******@test.co.in',
            subject: "Send Email Using Node.js",
            text: "Node.js New world for me",
            html: ""
        }
电子邮件中的预期输出

id  name  age  gender
1   abc    10   M
2   def    20   M

例如,您可以有多种npm包。检查这个

const cTable = require('console.table');
const table = cTable.getTable([
  {
    name: 'foo',
    age: 10
  }, {
    name: 'bar',
    age: 20
  }
]);

console.log(table);

您需要一个可以将对象数组转换为html的包。像这样的东西可以达到目的。基本上通过数据转换功能,它会给你适当的html,可以通过发送电子邮件发送。电子邮件将作为适当的表格呈现。希望这有帮助。

我正在使用类似的东西,但我只得到了最后一张唱片

for (let index = 0; index < data.rows.length; index++) {
            const element = data.rows[index];
            //console.log(element)
            //console.log(element.id);

            var mail = {
                from: 'xxx@outlook.com',
                to: 'xxxxs@gmail.co.in',
                subject: `Daily AWS validation check for the ${new Date().getTime()}`,
                html: `<h1> Hello Team, Here is the hourly data pull</h1> <br> <table><tr> <th>Hoursdata</th> <th>Book_Counts</th> <th>Search_Counts</th> <th>Hit_Counts</th> <tr><td>${element.run_hour}</td> <td>${element.book_counts}</td> <td>${element.search_counts}</td> <td>${element.hit_counts}</td></tr> </table>`
            }
        }
for(让index=0;indexHoursdata Book\u Counts Search\u Counts Hit\u Counts${element.run\u hour}${element.Book\u Counts}${element.Search\u Counts}${element.Hit\u Counts}`
}
}

你能给我看看'data'(console.log(data))行中的数据吗:[匿名{id:3,姓名:'c',薪水:50},匿名{id:1,姓名:'k',薪水:100},匿名{id:6,姓名:'e',薪水:90},匿名{id:4,姓名:'d',薪水:90},匿名{id:2,姓名:'b',薪水:10},匿名{id:5,姓名:'e',薪水:1000}]您考虑过使用视图引擎吗?我相信这会让它更容易。从您的数据创建一个html表,然后将该表放到您的电子邮件内容中。您必须安装console.table包npm install console.table--保存少量数据好的,如果我有20多个数据,那么最好从json创建csv/excel,这样可以被邮件缠住