S
S
skela232019-01-15 12:24:14
PostgreSQL
skela23, 2019-01-15 12:24:14

Connecting to postgresql from node.js?

I am making an example of connecting to a database
const {Client} = require('pg');
const db = new Client({
user:'postgres',
host:'localhost',
password:'12345',
port:5432
})
db.connect()
db.query('SELECT * FROM students',(err, data ) =>{
console.log(err, data);
db.end()
})
I get a bunch of errors, what am I doing wrong, tell me
(node:14944) UnhandledPromiseRejectionWarning: error: ���� ������ "*******" �� ����������
at Connection.parseE (D:\nodejs\node_modules\pg\lib\connection.js:555:11)
at Connection.parseMessage ( D:\nodejs\node_modules\pg\lib\connection.js:380:19)
at Socket. (D:\nodejs\node_modules\pg\lib\connection.js:120:22)
at Socket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js :264:11)
at Socket.Readable.push (_stream_readable.js:219:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
(node:14944) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which
was not handled with .catch(). (rejection id: 1)
(node:14944) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
D:\nodejs\01-connect.js:13
if (err) throw new Error(err)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Lebedinsky, 2019-01-16
@Lebed71

What is hidden in the text of the error?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question