Есть такой кусок кода, который обращается к postgres базе данных:
app.post('/verification', function(req, res){
// проверка имени и пароля в БД
var results = [];
pg.connect(connectionString, (err, client, done) => {
if(err){
done();
console.log(err);
return res.status(500).json({ success: false, data: err });
}
var query = client.query('SELECT $values($1, $2) FROM items',
[req.body.name, req.body.pass]);
console.log('query: ', query);
query.on('row', (row) => {
done();
results.push(row);
console.log('results: ', results);
query.on('end', () => { client.end(); });
});
if(results)
res.redirect(303, '/profile');
else
res.redirect(303, '/login');
});
console.log('Name: ' + req.body.name);
console.log('Password: ' + req.body.pass);
});
В результате чего я получаю в консоли ошибку
events.js:141
throw er; // Unhandled 'error' event
error: syntax error at or near "$"
at Connection.parseE (/home/user/IdeaProjects/artDress/node_modules/pg/lib/connection.js:554:11)
at Connection.parseMessage (/home/user/IdeaProjects/artDress/node_modules/pg/lib/connection.js:381:17)
at Socket. (/home/user/IdeaProjects/artDress/node_modules/pg/lib/connection.js:117:22)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:146:16)
at Socket.Readable.push (_stream_readable.js:110:10)
at TCP.onread (net.js:523:20)
А в браузере
Unable to connect