Created
October 8, 2022 17:45
-
-
Save barisbll/f5d9fb0bebe16a9b48302ee7b3d092d5 to your computer and use it in GitHub Desktop.
Usage of our singleton express application in index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Express } from 'express'; | |
import config from './config/config'; | |
import AppDataSource from './config/data-source'; | |
import logger from './config/logger'; | |
import { errorHandler } from './util/customError'; | |
import { Server } from './util/Server'; | |
const app = Server.getServer(); | |
// eslint-disable-next-line no-shadow | |
const initializeDB = async (app: Express) => { | |
try { | |
AppDataSource.initialize().then(() => { | |
app.listen(config.port || 8080, () => { | |
logger.info(`Server started at http://localhost:${config.port}`); | |
}); | |
}); | |
} catch (error) { | |
logger.error(error); | |
throw error; | |
} | |
}; | |
initializeDB(app); | |
app.use(errorHandler); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment