Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require("express");
- const databaseConfig= {
- "host": "localhost",
- "port": 5432,
- "database": "library_app",
- "user": "postgres"
- };
- const pgp = require("pg-promise")({});
- const db = pgp(databaseConfig);
- const app = express();
- const port = 5000;
- app.listen(port, (err) => {
- console.log(`running server on port: ${port}`);
- });
- const db = pgp(connection);
- const initOptions = {
- // global event notification;
- error: (error, e) => {
- if (e.cn) {
- // A connection-related error;
- //
- // Connections are reported back with the password hashed,
- // for safe errors logging, without exposing passwords.
- console.log('CN:', e.cn);
- console.log('EVENT:', error.message || error);
- }
- }
- };
- const pgp = require('pg-promise')(initOptions);
- // using an invalid connection string:
- const db = pgp('postgresql://userName:password@host:port/database');
- db.connect()
- .then(obj => {
- obj.done(); // success, release the connection;
- })
- .catch(error => {
- console.log('ERROR:', error.message || error);
- });
- db.proc('version')
- .then(data => {
- // SUCCESS
- // data.version =
- // 'PostgreSQL 9.5.1, compiled by Visual C++ build 1800, 64-bit'
- })
- .catch(error => {
- // connection-related error
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement