Skip to content

Instantly share code, notes, and snippets.

@IngIeoAndSpare
Last active April 19, 2019 01:22
Show Gist options
  • Save IngIeoAndSpare/9576a4150fd1678bf887042db6ab531d to your computer and use it in GitHub Desktop.
Save IngIeoAndSpare/9576a4150fd1678bf887042db6ab531d to your computer and use it in GitHub Desktop.
postgresql connect and test use pg module
{
"user" : "{{USER_NAME}}",
"userPW" : "{{USER_PASSWORD}}",
"host" : "{{DB_HOST}}",
"dbName" : "{{DB_NAME}}",
"port" : "{{PORT}}"
}
const {Client} = require('pg'),
fs = require('fs');
var client;
module.exports = {
settingDbConnection : function () {
const thisApp = this;
fs.readFile('./dbInfo.json', function(err, data){
if(err) {
console.log(err);
return;
}
let dbInfoData = JSON.parse(data);
client = new Client({
user : dbInfoData.user,
password : dbInfoData.userPW,
host : dbInfoData.host,
database : dbInfoData.dbName,
port : dbInfoData.port
});
thisApp.connectionDB();
});
},
connectionDB : function () {
client.connect();
client.query('{{QUERRY}}', (err, result) => {
if(!err) {
console.log(err);
}
console.log(result);
client.end();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment