-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
58 lines (52 loc) · 1.74 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
46
47
48
49
50
51
52
53
54
55
56
57
58
//getting all the enviroment variables
require('dotenv').config();
//creating an express app and requiring all the node modules
const express = require('express');
const app = express();
const router = express.Router();
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const flash = require("express-flash");
const session = require("express-session");
const passport = require("passport");
const methodOverride = require('method-override');
const appRoutes = require("./routes/appRoutes");
const cron = require('node-cron');
const settingRoutes = require("./routes/settingRoutes");
const DBURI = "mongodb+srv://<username>:<password>@cluster0.6wkxh.mongodb.net/test?retryWrites=true&w=majority";
const port = process.env.PORT || 3000;
const { sendMail } = require("./middleware/mailer");
const cors = require('cors');
//connecting to the database and listening to the port
mongoose
.connect(DBURI, { useNewUrlParser: true, useUnifiedTopology: true })
.then(app.listen(port))
.catch((err) => console.log(err));
//setting the express app
app.set('view engine', 'ejs');
app.use(express.static("public"));
app.use(express.urlencoded({ extended: true }));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(flash());
app.use(express.json());
app.use(cors());
app.use(session({
secret: "secret",
resave: false,
saveUninitialized: false
}));
//initialize passport
app.use(passport.initialize());
app.use(passport.session());
app.use(methodOverride('_method'))
//scheduler for running check everyday at 12:00
cron.schedule('0 0 0 * * *', () => {
sendMail();
});
//routes
app.use(appRoutes);
app.use(settingRoutes);
//404
router.use((req, res) => {
res.render('404.ejs', { title: '404 Error hai', alrt: '' });
});