mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 01:41:24 -06:00
26 lines
801 B
TypeScript
26 lines
801 B
TypeScript
import mongoose from 'mongoose';
|
|
|
|
import { configService, Database } from '../config/env.config';
|
|
import { Logger } from '../config/logger.config';
|
|
|
|
const logger = new Logger('MongoDB');
|
|
|
|
const db = configService.get<Database>('DATABASE');
|
|
export const dbserver = (() => {
|
|
if (db.ENABLED) {
|
|
logger.verbose('connecting');
|
|
const dbs = mongoose.createConnection(db.CONNECTION.URI, {
|
|
dbName: db.CONNECTION.DB_PREFIX_NAME + '-whatsapp-api',
|
|
});
|
|
logger.verbose('connected in ' + db.CONNECTION.URI);
|
|
logger.info('ON - dbName: ' + dbs['$dbName']);
|
|
|
|
process.on('beforeExit', () => {
|
|
logger.verbose('instance destroyed');
|
|
dbserver.destroy(true, (error) => logger.error(error));
|
|
});
|
|
|
|
return dbs;
|
|
}
|
|
})();
|