-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (37 loc) · 1.24 KB
/
index.js
File metadata and controls
41 lines (37 loc) · 1.24 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
// @ts-nocheck
require("dotenv").config("./.env");
const express = require("express");
const connectDB = require("./src/DBconfig/connect");
const logger = require("./src/utils/logger");
const config = require("config");
const userRoutes = require("./src/routes/userRoutes");
const profileRoutes = require("./src/routes/profileRoutes");
const bankingRoutes = require("./src/routes/bankingRoutes");
const app = express();
connectDB();
//if no secret key for token generation is found,
//automatically shutdown the app
if (!process.env.secretKey) {
logger.error("FATAL ERROR: secretKey is not defined.");
process.exit(1);
}
//handling uncaught exception
process.on("uncaughtExceptions", (ex) => {
logger.error("caught an uncaughtExceptions,", ex.message);
process.exit(1);
});
//handling unhandled exceptions
process.on("unhandledRejection", (ex) => {
logger.error("unhandled rejection", ex.message, ex);
process.exit(1);
});
app.use(express.json());
app.use("/api/auth/", [userRoutes]);
app.use("/api/users/", [profileRoutes]);
app.use("/api/transactions", bankingRoutes);
app.set("view engine", "ejs");
app.set("views", "./src/views/");
const PORT = config.get("PORT") || 3000;
app.listen(PORT, () => {
logger.info(`Server running on port ${PORT}`);
});