Commit 20aea18b authored by Цой Данил's avatar Цой Данил 💬

#1 added mongo and connected to it. Planning to go to next step

parent bfe15b20
export const enum EStatuses {
SUCCESS = 'Success',
FAILURE = 'Failure'
}
\ No newline at end of file
...@@ -2,6 +2,7 @@ import express, { Express } from "express"; ...@@ -2,6 +2,7 @@ import express, { Express } from "express";
import dotenv from 'dotenv'; import dotenv from 'dotenv';
import cors from 'cors'; import cors from 'cors';
import { HealthCheckController } from "./controllers/healthCheck"; import { HealthCheckController } from "./controllers/healthCheck";
import { mongooseDB } from "./repository/mongooseDB";
dotenv.config() dotenv.config()
...@@ -18,7 +19,11 @@ class App { ...@@ -18,7 +19,11 @@ class App {
try{ try{
this.app.use('/health-check', new HealthCheckController().getRouter()) this.app.use('/health-check', new HealthCheckController().getRouter())
this.app.listen(process.env.APP_PORT, () => { this.app.listen(process.env.APP_PORT, () => {
console.log(`Server is running on port ${process.env.APP_PORT}`) console.log(`Server is running on http://localhost:${process.env.APP_PORT}`)
})
await mongooseDB.init()
process.on('exit', () => {
mongooseDB.close()
}) })
} catch(err: unknown){ } catch(err: unknown){
console.log(err); console.log(err);
......
import { EStatuses } from "../enum/EStatuses";
export default interface IResponse<T = null> {
status: EStatuses
result: T
message: string
}
\ No newline at end of file
import dotenv from 'dotenv';
import mongoose, { Mongoose } from 'mongoose';
dotenv.config();
export class MongooseDB {
private client: Mongoose | null = null
public close = async() => {
if (!this.client) return
await this.client.disconnect();
}
public init = async (): Promise<void> => {
try {
this.client = await mongoose.connect(process.env.MONGO_CLIENT_URL || '')
console.log('Server connected to MongoDB');
} catch (err) {
const error = err as Error;
console.error('Connected error MongoDB:', error);
}
}
}
export const mongooseDB = new MongooseDB()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment