Привет! Следую инструкциям из интернета, но всё не получается. Вылетает ошибка после селекта:
Error: Connection terminated
at Connection.con.once (/Users/olegostashov/Documents/Study/PMIS/node_modules/pg/lib/client.js:170:29)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:111:20)
at Connection.emit (events.js:208:7)
at Socket.<anonymous> (/Users/olegostashov/Documents/Study/PMIS/node_modules/pg/lib/connection.js:122:10)
at emitNone (events.js:111:20)
at Socket.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
Что не так? Использую node-postgres v7.4.1. Содержимое моего файла app.js:
const express = require("express");
const bodyParser = require("body-parser");
const config = require("./config");
const pg = require("pg");
const pg_connect = {
user: config.user,
host: config.host,
database: config.database,
password: config.password,
port: config.port_pg
};
const app = express();
app.set("view engine", "ejs");
app.use(bodyParser.urlencoded({ extended: true }));
app.get("/", (req, res) => {
var pool = new pg.Pool(pg_connect);
const results = [];
pool.connect(function(err, client, done) {
if (err) {
done();
console.log(err);
return res.status(500).json({ success: false, data: err });
} else {
client.query("SELECT * FROM users", (err, res) => {
console.log(err);
});
done();
}
console.log(results);
res.render("index", { users: results });
});
pool.end();
});
module.exports = app;