-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (40 loc) · 1.05 KB
/
index.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
const express = require("express");
const app = express();
// Utilities
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
// Config variables
require("dotenv").config();
const {MONGOURI} = process.env;
// Setting the EJS engine
app.set("view engine", "ejs");
app.use(express.static("public"));
// To get data in JSON format
app.use(bodyParser.urlencoded({extended: true}));
// Connecting to the database
mongoose.promise = global.Promise;
console.log(MONGOURI);
mongoose.connect(
MONGOURI,
{
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true
},
(err, db) => {
if (err) console.log(err);
else console.log("Database Connected...");
}
);
// Test route
app.get("/api", async (req, res) => {
return res.status(200).json({message: "API running..."});
});
// Mounting the routes
app.use("/", require("./routes/index"));
// Starting the server
const PORT = process.env.PORT || 5000;
app.listen(PORT, function () {
console.log(`Server running on port ${PORT}`);
});