1. 배경
Node.js 기반으로 PostgreSQL 연동하여 작업 실행.
2. pg 설치
npm install pg
3. Connection Pool
const { Pool } = require('pg')
const pool = new Pool({
user: 'malladmin',
host: '[DB주소]',
database: 'malldb',
password: 'mall00',
port: 5432,
})
4. 데이터 삽입 테스트
const add_sql = 'INSERT INTO data_log ( currenttime, service, data_name, value ) VALUES ( default, $1, $2, $3 )';
pool.query(add_sql, ['test1', 'test2', 'test3'], (err, res) => {
if (err) {
throw err
}
console.log('response:', res.rows[0])
})
