console.log('wrok'); const pg = require('pg'); const config = { host: '77.34.74.77', // Do not hard code your username and password. // Consider using Node environment variables. user: 'postgres', password: 'postgres', database: 'postgres', port: 5432, ssl: false }; const client = new pg.Client(config); client.connect ( err => { if (err) throw err; else { addToDvachDatabase(); queryDatabase(); } } ); function addToDvachDatabase() { //Добавляем значение в базу данных dvach console.log(`Running query to PostgreSQL server: ${config.host}`); const query = "INSERT INTO dvach (post) VALUES ('Привет двач');"; client.query(query) .then(res => { //const rows = res.rows; //rows.map(row => { //console.log(`Прочитано следующее : ${JSON.stringify(row)}`); // }); //process.exit(); }) .catch(err => { console.log(err); }); } function queryDatabase() { //VSE ZNACHENIYA IZ BAZI DANNYKH console.log(`Running query to PostgreSQL server: ${config.host}`); const query = 'SELECT * FROM dvach;'; client.query(query) .then(res => { const rows = res.rows; rows.map(row => { console.log(`Прочитано следующее : ${JSON.stringify(row)}`); }); process.exit(); }) .catch(err => { console.log(err); }); }