-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.ts
35 lines (27 loc) · 886 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
31
32
33
34
35
import express, { Express, Request, Response } from "express";
import helmet from "helmet";
import dotenv from "dotenv";
import { checkDbConnection, httpLogger, useCors } from "./src/middlewares";
import { db, initateDB } from "./src/database";
dotenv.config();
const app: Express = express();
const port = process.env.PORT;
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(httpLogger());
app.use(helmet());
app.use(useCors());
app.get("/", (req: Request, res: Response) => {
res.send("Express + TypeScript Server.")
});
initateDB();
app.use(checkDbConnection());
app.listen(port, () => {
console.log(`⚡️[server]: Server is running at https://localhost:${port}`);
});
process.on("SIGINT", function () {
db.close(function () {
console.log("Mongoose connection disconnected through app termination");
process.exit(1);
});
});