-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
47 lines (36 loc) · 1.14 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
const express = require("express");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const helmet = require("helmet");
require('dotenv').config();
var apiRoutes = require("./routes/api.js");
const auth = require("./routes/auth.js");
const app = express();
app.set("view engine", "ejs");
app.use(helmet());
console.log("Server js file is loaded");
// Database mongoose connection
mongoose.connect(process.env.DB, {
useNewUrlParser: true,
useFindAndModify: false,
useCreateIndex: true,
useUnifiedTopology: true
}).catch(err => console.log(err));
let db = mongoose.connection;
db.on("error", console.error.bind(console, "MongoDB connection error:"));
// to determine the directories for other files
app.use(express.static(__dirname));
//Bodyparser setup
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
auth(app);
apiRoutes(app);
app.use(function(req, res, next) {
res.status(404)
.type('text/html')
.sendFile(process.cwd() + "/404.html");
});
let port = process.env.PORT || 1234;
app.listen(port , function () {
console.log("Listening on port " + port);
});