I am refactoring mongoose code with postgresql.
I am using express and pg.
I am very new to node-postgresql and pg Pool.
this is what I am having in db.js
file.
import pg from 'pg';
const {Pool} = pg;
const pool = new Pool({
user: 'admin',
password: 'admin',
host: 'localhost',
port: 5432,
database: 'workoutsdb'
})
export default pool;
I want to check if the provided details are correct. Is there a way to test it?
this is my server.js
file contents
import express from 'express';
import cors from 'cors';
import workoutsRouter from './routes/workoutsRouter.js';
import pool from './db.js';
// Express app
const app = express();
// Middleware
app.use(express.json());
app.use(cors());
app.use((req, res, next) => {
next();
})
// routes
app.use('/api', workoutsRouter)
let connection;
// here I want to implement the logic
// try {
// const client = await pool.connect();
// if (client) {
// connection = true;
// }
// } catch (error) {
// console.log(error);
// }
if (connection) {
app.listen(3001, () => {
console.log('conncted to db & listening on port 3001')
})
}