connect.js 369 B

123456789101112131415161718192021
  1. const { Client } = require('pg')
  2. const client = new Client({
  3. user: 'postgres',
  4. host: 'localhost',
  5. database: 'testdb',
  6. password: '1234abcd',
  7. port: 5432,
  8. });
  9. client.connect()
  10. client.query('SELECT NOW()', (err, res) => {
  11. if (err) {
  12. console.error(err);
  13. return;
  14. }
  15. console.log('Connection successful');
  16. client.end()
  17. });