-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
30 lines (25 loc) · 881 Bytes
/
server.ts
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
import express, { Application, json } from 'express'
import { dbConnection } from './src/db/config/db.connection';
import route from './src/routes/index'
import {} from 'dotenv/config'
const PORT = process.env.PORT;
const createServer = async (): Promise<Application | void> => {
try {
const server: Application = express();
server.use(json());
server.use(route);
return server
} catch (error) {
return console.log('Error while creating server:', error);
}
}
const startServer = async (server: Application): Promise<void> => {
try {
server.listen(PORT);
await dbConnection()
console.log(`====================Server started on port ${PORT}====================`);
} catch (error) {
return console.log('Error while starting server:', error);
}
}
export { createServer, startServer };