2017-09-29 1 views
1

https://github.com/voxpelli/node-connect-pg-simple 쇼에 대한 간단한 예 :connect-pg-simple에서 연결 문자열을 지정하는 방법은 무엇입니까?

var session = require('express-session'); 

app.use(session({ 
    store: new (require('connect-pg-simple')(session))(), 
    secret: process.env.FOO_COOKIE_SECRET, 
    resave: false, 
    cookie: { maxAge: 30 * 24 * 60 * 60 * 1000 } // 30 days 
})); 

그러나 나는 그것을 시도 할 때, 노드는 불평 :

던져 새로운 오류 ('세부 사항을 연결 없음 데이터베이스가 에 제공되지 연결-PG-간단한') ;

어떻게 연결 문자열을 지정합니까?

답변

2
// I was stuck with the same proble and solved it 

    // 1-) Connection details 
    const conObject = { 
     user: 'mehmood', 
     password: 'mehmood', 
     host: 'localhost',// or whatever it may be 
     port: 5432, 
     database: 'test_db' 
    }; 

    // 2-) Create an instance of connect-pg-simple and pass it session 
    const pgSession = require('connect-pg-simple')(session); 

    // 3-) Create a config option for store 
    const pgStoreConfig = { 
     pgPromise: require('pg-promise')({ promiseLib: require('bluebird') })({ 
         conObject }), // user either this 
     //conString: 'postgres://mehmood:[email protected]:5432/test_db', // or this 
     // conObject: conObject,// or this, 
     // pool: new (require('pg').Pool({ /* pool options here*/}))// or this 

    } 
    // 4-) use the store configuration to pgSession instance 
    app.use(session({ 
     store: new pgSession(pgStoreConfig), 
     secret: 'jW8aor76jpPX', // session secret 
     resave: true, 
     saveUninitialized: true, 
     cookie: { maxAge: 30 * 24 * 60 * 60 * 1000 } // 30 days 
    })); 


    // Share improve this answer 
관련 문제