【发布时间】:2019-08-02 20:49:28
【问题描述】:
我制作了一个简单的 JS 文件来托管本地服务器,然后使用 Node 读取数据库并返回结果。我的目标是创建一个只返回行的页面,然后可以创建新的。
问题是控制台记录了结果,但服务器没有连接。我可以制作仅托管服务器的文件,但放入查询会阻止服务器运行。如何让我的查询在服务器上运行?
代码如下:
const pg = require("pg");
const pool = new pg.Pool({
user: "James",
host: "127.0.0.1",
database: "makersBnb",
password: "",
port: "5432"});
pool.query('SELECT * FROM listings', (err, res) => {
console.log(err, res);
pool.end();
});
表格有 2 行。 这是控制台:
Result {
command: 'SELECT',
rowCount: 2,
oid: null,
rows:
[ { id: 2,
listing_name: 'testListing',
price: '5',
description: 'description',
owner_name: 'me',
email: 'private@email.com',
phone_num: '07777777771' },
{ id: 1,
listing_name: 'a',
price: 'b',
description: 'c',
owner_name: 'd',
email: 'e',
phone_num: 'f' } ],
_parsers:
[ [Function: parseInteger],
[Function: noParse],
[Function: noParse],
[Function: noParse],
[Function: noParse],
[Function: noParse],
[Function: noParse] ],
RowCtor: null,
rowAsArray: false,
_getTypeParser: [Function: bound ] }
【问题讨论】:
标签: javascript node.js database server