Skip to content

Instantly share code, notes, and snippets.

@barisbll
Created October 8, 2022 17:45
Show Gist options
  • Save barisbll/f5d9fb0bebe16a9b48302ee7b3d092d5 to your computer and use it in GitHub Desktop.
Save barisbll/f5d9fb0bebe16a9b48302ee7b3d092d5 to your computer and use it in GitHub Desktop.
Usage of our singleton express application in index.ts
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