Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
new connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Dorschner authored and Guillaume Dorschner committed Oct 20, 2023
1 parent 9c8a8eb commit b321a09
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,42 @@ const cors = require('cors');
const path = require('path');
const session = require('express-session');
const multer = require('multer');
const {connectDatabase} = require('./database/setupDb');



const { Client } = require('pg');

const connectDatabase = async () => {
// Read configuration from environment variables
const dbHost = process.env.DB_HOST || 'localhost';
const dbPort = process.env.DB_PORT || 5432;
const dbUser = process.env.DB_USER || 'root';
const dbPassword = process.env.DB_PASSWORD || 'rootpassword';
const dbName = process.env.DB_NAME || 'my_database';

// Create a client for database connection
const rootClient = new Client({
host: dbHost,
port: dbPort,
user: dbUser,
password: dbPassword,
database: dbName
});

try {
// Connect to the database
await rootClient.connect();
console.log('Connected to the database successfully!');
} catch (err) {
console.error('Failed to connect to the database:', err);
}
};

// Call the function to connect to the database
connectDatabase();




const app = express();

Expand Down

0 comments on commit b321a09

Please sign in to comment.