-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
47 lines (38 loc) · 1.37 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
// DEPENDENCIES
const express = require('express');
const mongoose = require('mongoose');
const path = require("path");
const passport = require('passport');
require('dotenv').config();
// Enables the use of ES6 import statements throughout our application. (ESM Package)
require = require("esm")(module/*, options*/);
// REQUIRE CONFIG DATA
const addMiddleware = require("./config/middleware.js");
const addPassport = require("./config/passport.js");
const addLocalStrategy = require("./config/strategies/strategy.js");
// REQUIRE OUR MODELS
const User = require('./src/models/user');
const app = express();
// Implement ejs template engine to render html file from views folder
app.set("views", path.join(__dirname, "./views"));
app.set("view engine", "ejs");
//MIDDLEWARE
addMiddleware(app, express);
//PASSPORT + LOCAL STARTEGY
addPassport(passport, User);
addLocalStrategy(passport, User);
// CONNECT TO EXPRESS SERVER, THEN TO MongoDB
app.listen(process.env.PORT || 5000, (err, res) => {
if (err) console.log(err);
console.log("Server is listening on port 5000 at: http://localhost:5000");
mongoose.connect(process.env.URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: true,
}).then(() => {
console.log("Connected to mongoDB!");
},
err => { console.log(err) },
);
});