-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
48 lines (41 loc) · 1.43 KB
/
index.ts
File metadata and controls
48 lines (41 loc) · 1.43 KB
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, Request, Response } from "express";
import cors from "cors";
import mongoose from "mongoose";
import user from "./routes/userRoute";
import question from "./routes/testRoute";
const app: Application = express();
const port: number = 2255;
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cors());
app.use("/api", user);
app.use("/api/test", question);
app.use("/", (req: Request, res: Response) => {
res.status(200).json({ message: "Welcome" });
});
// mongodb+srv://shecodesaj:<password>@cluster0.xe1jgnf.mongodb.net/?retryWrites=true&w=majority
// mongodb+srv://brighterdayscodelab:brighterdayscodelab@cluster0.upn8ipm.mongodb.net/newIntakeDB?retryWrites=true&w=majority
mongoose
.connect(
"mongodb+srv://shecodesaj:shecodesaj@cluster0.xe1jgnf.mongodb.net/newIntakeDB?retryWrites=true&w=majority"
)
.then(() => {
const server = app.listen(process.env.PORT || port, () => {
console.log("server up and running!");
});
process.on("uncaughtException", (err: Error) => {
console.log("shuttin down server bcos: uncaughtException");
console.log(err);
process.exit(1);
});
process.on("unhandledRejection", (reason: any) => {
console.log("shuttin down server bcos: unhandledRejection");
console.log(reason);
server.close(() => {
process.exit(1);
});
});
})
.catch((err) => {
console.log(err);
});