-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
43 lines (35 loc) · 1.43 KB
/
server.ts
File metadata and controls
43 lines (35 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import winston from 'winston';
import { MongooseManager } from './src/configs/mongooseManager.config.js';
import { GracefulShutdownManager } from './src/utils/gracefulShutdownManager.util.js';
import app from './src/app.js';
import { env } from './src/configs/env.config.js';
const PORT = Number(env.app.PORT);
const logger = winston.createLogger({
level: 'info',
format: winston.format.combine(winston.format.timestamp(), winston.format.json()),
transports: [
new winston.transports.Console(),
new winston.transports.File({ filename: 'logs/error.log', level: 'error' }),
new winston.transports.File({ filename: 'logs/combined.log' })
]
});
const startApplication = async () => {
try {
logger.info('Starting Lapbee E-Commerce application...');
// Connecting mongoDB with mongoose
const mongooseManager = MongooseManager.getInstance(logger);
await mongooseManager.connect();
// Start HTTP Server
const server = app.listen(PORT, (error) => {
if (error) throw error;
logger.info(`Server running on port: ${PORT}`);
});
new GracefulShutdownManager({ httpServer: server, mongooseConnection: mongooseManager.getConnection() }, logger);
} catch (error) {
logger.error('Failed to start application...');
logger.error(`Error failed start application: `, error);
const manager = new GracefulShutdownManager({}, logger);
await manager.initiateShutdown();
}
};
await startApplication();