-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
36 lines (26 loc) · 815 Bytes
/
Copy pathserver.js
File metadata and controls
36 lines (26 loc) · 815 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
require("dotenv").config();
const express = require("express");
const dotenv = require("dotenv");
const connectDatabase = require("./helpers/database/connectDatabase");
const customErrorHandler = require("./middlewears/errors/customErrorHandler");
const routers = require("./routers");
const path = require("path");
// 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}`);
});