-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
36 lines (30 loc) · 768 Bytes
/
server.ts
File metadata and controls
36 lines (30 loc) · 768 Bytes
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
const dotenv = require("dotenv");
const App = require("./app.ts");
const mongoose = require("mongoose");
const http = require("./app.ts");
dotenv.config();
if (!process.env.DATABASE) {
throw new Error("Database URL must be set in .env file");
}
if (!process.env.DATABASE_PASSWORD) {
throw new Error("Database Password must be set in .env file");
}
const DB = process.env.DATABASE?.replace(
"<password>",
process.env.DATABASE_PASSWORD
);
mongoose
.connect(DB, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log("Database Connected");
})
.catch((err: any) => {
console.log(err);
});
const PORT = process.env.PORT || 4000;
http.listen(PORT, () => {
console.log("Server Started on Port", PORT);
});