Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module.exports = function (query) {
- const { Client } = require ('pg')
- const connection = {
- user: 'postgres',
- host: 'localhost',
- database : 'hoteltest',
- password: '1234',
- port: 5432
- }
- const client = new Client(connection)
- var datos;
- client.connect()
- client.query(query)
- .then (response => {
- datos = response.rows
- console.log(datos)
- return datos
- client.end()
- })
- .catch(err => {
- console.log(err)
- client.end()
- })
- }
- import data from './pg/index.js'
- var pgdata;
- pgdata = data('SELECT * FROM usuarios')
- console.log(pgdata)
Add Comment
Please, Sign In to add comment