forked from ALPHAVIO/WordNook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
45 lines (36 loc) · 1.33 KB
/
app.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
//jshint esversion:6
//Acquiring Dependencies-
const express = require("express");
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const ejs = require("ejs");
const mongoose = require('mongoose');
const _ = require("lodash");
const PORT = process.env.PORT || 3000;
const auth = require('./middlewares/auth');
const Blog = require('./models/Blog.model')
//Setting up the app and the ejs view engine-
const app = express();
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static("public"));
app.use(express.json());
app.use(cookieParser());
//When in development mode then only require the dotenv module
if (process.env.NODE_ENV !== 'production') {
const dotenv = require('dotenv');
dotenv.config({ path: './.env' });
}
//Connecting to Mongo Database using ODM Mongoose-
const URL = process.env.URL;
mongoose.connect(URL, { useNewUrlParser: true, useUnifiedTopology: true });
// Router for user login and sign in
app.use(require("./routes/user.router"));
//router for post and search related urls
app.use(require("./routes/post.router"));
// router for the requests from home page
app.use(require("./routes/index.router"));
//Launching the server on port 3000 in development mode-
app.listen(PORT, function () {
console.log("Server started on port 3000");
});