forked from bezkoder/express-typescript-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.ts
29 lines (27 loc) · 827 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
import express, { Application } from "express";
import Server from "./src/index";
import mongoose from "mongoose";
const app: Application = express();
const server: Server = new Server(app);
const PORT: number = process.env.PORT ? parseInt(process.env.PORT, 10) : 4561;
const mongoUrl = 'mongodb://127.0.0.1:27017/test';
const mongooseConnection = mongoose.connect(mongoUrl);
mongooseConnection.then(
() => {
console.log("Connected to mongo db server");
app
.listen(PORT, "localhost", function () {
console.log(`Server is running on port ${PORT}.`);
})
.on("error", (err: any) => {
if (err.code === "EADDRINUSE") {
console.log("Error: address already in use");
} else {
console.log(err);
}
});
},
(err) => {
console.log(err);
}
)