app.js | LogSyS
/app.js
const express = require('express');
const app = express();
const mongoose = require('mongoose');
const router = express.Router();
const MongoClient = require('mongodb').MongoClient
const bodyParser = require('body-parser');
const session = require('express-session');
// const expressValidator = require('express-validator');
const flash = require('connect-flash');
const passport = require('passport');
// var MongoStore = require('connect-mongo')(session);
mongoose.connect('mongodb://localhost:27017/EmployeeDB', {useNewUrlParser: true, useUnifiedTopology: true}, (err) => {
if(mongoose.connect){console.log('Success! MongoDB Connected..')}
else{console.log('Error in Db connection : ' + err)}
});
// passport config
require('./config/passport')(passport);
//view engine
app.set('view engine', 'pug')
// express session midlware
app.use(
session({
secret: 'secret',
resave: true,
saveUninitialized: true
})
);
// passport middleware
app.use(passport.initialize());
app.use(passport.session());
// connect flash midlware
// app.use(flash());
// Express Messages Middleware
app.use(require('connect-flash')());
app.use(function (req, res, next) {
res.locals.messages = require('express-messages')(req, res);
next();
});
app.use(express.urlencoded({ extended : false }));
// parse application/json
app.use(bodyParser.json());
//routes
app.use(router);
app.use('/', require('./routes/index'));
app.listen(3000, () => {
console.log('Express Server Started At Port : 3000');
});
Comments
Post a Comment