-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
76 lines (61 loc) · 2.2 KB
/
index.js
File metadata and controls
76 lines (61 loc) · 2.2 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const express = require('express'); // requiring express,
const port = 8000; // assigning port, so that I can try and test as this post,
const app = express();
// requiring express-ejs-layout, it will help in rendering the page.
const expressLayout = require('express-ejs-layouts');
// requring DataBase
const db = require('./config/mongoose');
const bodyParser = require('body-parser');
// Creating session
const session = require('express-session');
const passport = require('passport');
const passportLocal = require('./config/passport-local');
// requiring mongo-store, so that we can use the existing user even after server start
const MongoStore = require('connect-mongo');
// they are used for showing action notifications
const flash = require('connect-flash');
const flashMiddleWare = require('./config/flashMiddleware');
// For getting the output from req.body(it will parse the upcoming request to String or Arrays).
app.use(bodyParser.urlencoded({extended:false}));
// For using the file in assets folder.
app.use(express.static('./assets'));
// Setting up the view engine
app.set('view engine','ejs');
app.set('views','./views');
app.use(expressLayout);
// mongo store is used to store the session cookie in the db
app.use(session({
name: "Employee_Review_System",
// change secret during before deployment in production
secret: "ERS",
saveUninitialized: false,
resave: false,
cookie: {
maxAge: (1000 * 60 * 100)
},
store: MongoStore.create({
mongoUrl: 'mongodb+srv://amansingh60046:Aman1704@acoding1704.3iujmoc.mongodb.net/',
autoRemove: 'disabled'
},
(err) => {
console.log(err || 'connect-mongo setup ok');
}
)
}))
// Using passport
app.use(passport.initialize());
app.use(passport.session());
app.use(passport.setAuthenticatedUser);
// Using Connect flash
app.use(flash());
app.use(flashMiddleWare.setFlash);
// setting up the router, following MVC structure.
app.use('/' , require('./routes/index'));
// Setting up the server at the given port
app.listen(port, function(err){
if(err){
console.log("Error in running the app.");
return ;
}
console.log("Server is up and running at port ", + port);
});