-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
40 lines (25 loc) · 799 Bytes
/
server.js
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
const express = require("express");
const dotenv = require("dotenv");
const connectDatabase = require("./helpers/database/connectDatabase");
const customErrorHandler = require("./middlewares/errors/customErrorHandler");
const path = require("path");
const routers = require("./routers/index");
// Enviroment Variables
dotenv.config({
path: "./config/env/config.env",
});
// MongoDb Connection
connectDatabase();
const app = express();
// Express - body middleware
app.use(express.json());
const PORT = process.env.PORT;
// Routers Middleware
app.use("/api", routers);
// Error Handler
app.use(customErrorHandler);
//Static files
app.use(express.static(path.join(__dirname, "public")));
app.listen(PORT, () => {
console.log(`App Started On ${PORT} : ${process.env.NODE_ENV}`);
});