-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
53 lines (47 loc) · 1.28 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
51
52
53
// Requiring dependencies
const express = require("express");
const mongoose = require("mongoose");
const dotenv = require("dotenv");
const cors = require("cors");
const path = require("path");
const cookieParser = require("cookie-parser");
const bodyParser = require("body-parser");
const router = require("./routes");
const multer = require("multer");
const upload = multer();
// Loading env variables
dotenv.config();
// Initializing the app
const app = express();
// Setting static files and view engine
app.set("view engine", "ejs");
app.use(express.static(path.join(__dirname, "public")));
app.use(express.static(path.join(__dirname, "public/css/")));
app.use(express.static(path.join(__dirname, "public/assests/")));
app.use(express.static(path.join(__dirname, "public/js/")));
// Middleware
app.use(express.json());
app.use(bodyParser.json());
app.use(
bodyParser.urlencoded({
extended: true,
})
);
app.use(
express.urlencoded({
extended: true,
})
);
app.use(cors());
app.use(cookieParser());
mongoose.connect(process.env.MONGO_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
});
const PORT = process.env.PORT || 5000;
app.use("/", router);
// Listening on port
app.listen(PORT, () => {
console.log(`Server started on PORT ${PORT}`);
});