-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
48 lines (40 loc) · 1.11 KB
/
app.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, { Application } from "express";
import { invoke } from "./src/routes";
import { env } from "./src/helpers/env";
import mongoose from "mongoose";
import cors from "cors";
import bodyParser from "body-parser";
const app: Application = express();
const port = env.PORT || 3000;
function middlewares() {
app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.json());
}
function connectMongDb() {
mongoose
.connect(env.MONGODB_URI as string, {
dbName: env.DB_NAME,
user: env.DB_USER,
pass: env.DB_PASS,
})
.then(() => {
console.log("Mongodb connected....");
})
.catch((err) => console.log(err.message));
mongoose.connection.on("connected", () => {
console.log("Mongoose connected to db...");
});
mongoose.connection.on("error", (err) => {
console.log(err.message);
});
mongoose.connection.on("disconnected", () => {
console.log("Mongoose connection is disconnected...");
});
}
middlewares();
connectMongDb();
app.use(invoke());
app.listen(port, () => {
console.log(`server init on this port: ${port}`);
});