Last active
          April 19, 2019 01:22 
        
      - 
      
 - 
        
Save IngIeoAndSpare/9576a4150fd1678bf887042db6ab531d to your computer and use it in GitHub Desktop.  
    postgresql connect and test use pg module
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | { | |
| "user" : "{{USER_NAME}}", | |
| "userPW" : "{{USER_PASSWORD}}", | |
| "host" : "{{DB_HOST}}", | |
| "dbName" : "{{DB_NAME}}", | |
| "port" : "{{PORT}}" | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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