TypeError:无法读取node.js中未定义的属性“ 0”

时间:2019-11-23 06:23:10

标签: node.js ubuntu mariadb

听3000 TypeError:无法读取未定义的属性“ 0”     在Object.GetUserList [作为getUserList](/home/ubuntu/mariaDBConn.js:22:20)     在processTicksAndRejections(internal / process / task_queues.js:93:5)

我正在尝试将MariaDB与Amazon EC2 ubuntu服务器中的Node.js绑定。

mariaDBConn.js

const mariadb = require('mariadb');

const pool = mariadb.createPool({
    host:'127.0.0.1',
        port:'3307',
    user:'test_user',  password:'1111',
    connectionLimit:5
});

async function GetUserList(){
    let conn, rows;
    try{
        conn = await pool.getConnection();
        conn.query('USE synctest');
        rows = await conn.query('SELECT * FROM pitchers');
    }
    catch(err){
        throw err;
    }
    finally{
        if (conn) conn.end();
        return rows[0];
    }

index.js

const mdbConn = require('./mariaDBConn.js')
const express = require('express');
const app = express();

mdbConn.getUserList()
  .then((rows) => {
    console.log(rows);
  })
  .catch((errMsg) => {
    console.log(errMsg);
  });

const port = process.env.PORT || 3000;
app.listen(port, () => {
  console.log(`listening on ${port}`);
});
  

节点index.js

我不知道为什么我失败了。 请赐教。

0 个答案:

没有答案