feat: postgres config

This commit is contained in:
karishmas6
2024-09-24 17:19:49 +05:30
parent d291f43c61
commit 31be279168

26
server/src/db/config.ts Normal file
View File

@@ -0,0 +1,26 @@
import { Sequelize } from 'sequelize';
import dotenv from 'dotenv';
dotenv.config();
const sequelize = new Sequelize(
process.env.DB_NAME as string,
process.env.DB_USER as string,
process.env.DB_PASSWORD as string,
{
host: process.env.DB_HOST,
dialect: 'postgres',
logging: false,
}
);
export const connectDB = async () => {
try {
await sequelize.authenticate();
console.log('Database connected successfully');
} catch (error) {
console.error('Unable to connect to the database:', error);
}
};
export default sequelize;