← back to Dw Scrape Scheduler
lib/db.js
17 lines
// Shared pg pool. Reads DW_ADMIN_DB_PASSWORD from the secrets .env (same pattern
// as scrape-astek.js) so no secret is hardcoded here.
const fs = require('fs');
const os = require('os');
const { Pool } = require('pg');
const PW = (() => {
try {
const env = fs.readFileSync(os.homedir() + '/Projects/secrets-manager/.env', 'utf8');
const m = env.match(/^DW_ADMIN_DB_PASSWORD=(.*)$/m);
return m ? m[1].replace(/^["']|["']$/g, '').trim() : (process.env.PGPASSWORD || '');
} catch { return process.env.PGPASSWORD || ''; }
})();
const pool = new Pool({ host: '127.0.0.1', port: 5432, user: 'dw_admin', database: 'dw_unified', password: PW });
module.exports = { pool };