-
Notifications
You must be signed in to change notification settings - Fork 6
/
server.js
50 lines (39 loc) · 1.13 KB
/
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
41
42
43
44
45
46
47
48
49
50
//Configuring Dotenv to use environment variables from .env file
require("dotenv").config();
//Import Modules
const path = require("path");
//Connecting the database
const connectDB = require("./config/db");
connectDB();
//Creating express server
const express = require("express");
const app = express();
//Specifying the port
const port = process.env.PORT || 5000;
//Serving Static Folder
app.use(
"/api/public/images",
express.static(path.join(__dirname, "/public/images"))
);
app.use("/v1/logs", express.static(path.join(__dirname, "/logs")));
// CORS Handler
const corsHandler = require("./middlewares/corsHandler");
app.use(corsHandler);
//Using Express.JSON
app.use(express.json());
//Routes
const indexRoutes = require("./routes/indexRoutes");
app.use("/api", indexRoutes);
// Error Handler
const errorHandler = require("./middlewares/errorHandler");
app.use(errorHandler);
//Scripts Scheduling
const cron = require("node-cron");
// Define a cron job that runs every 14 minutes
// cron.schedule("*/14 * * * *", () => {
// ...
// });
//Listening om the port
app.listen(port, () => {
console.log(`Listening on port ${port}`);
});