-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
48 lines (37 loc) · 1.16 KB
/
index.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
36
37
38
39
40
41
42
43
44
45
46
47
48
import express, { Express } from "express";
import env from "./utils/env";
import bodyParser from "body-parser";
import cors from "cors";
import mongoose from "mongoose";
import helmet from "helmet";
/* DB Imports */
import db from "./utils/config/mongodb";
/* Routers Import */
import Routers from "./app/routes";
/* Setup topmost layer of the application server -*/
const app: Express = express();
const port = env.node_env === "DEV" ? env.port.dev : env.port.prod;
/* Mongoose Config */
mongoose.Promise = global.Promise;
mongoose
.connect(db.url, { ignoreUndefined: false })
.then(() => {
console.log(`⚡️DB running - in ${env.node_env} environment`);
})
.catch((error) => {
console.log({ message: "DB Connection unsuccessfull", error });
});
/* Middleware */
/* Body Parser - for urlencoded and JSON */
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
/* CORS - Cross Origin Resources Sharing */
app.use(cors());
/* Helmet Config */
app.use(helmet());
/* Route Middleware */
app.use(Routers);
/* Start Server */
app.listen(port, () => {
console.log(`⚡️Server running in ${env.node_env} environment => ${port}`);
});