text: require('dotenv').config();
  const envs = process.env;
  const port = 3000;
  const path = require('path');
  const bodyParser = require('body-parser');
  const express = require('express');
  const app = express();
  const mongoose = require('mongoose');
  const ejsMate = require('ejs-mate');
  const session = require('express-session');
  const flash = require('connect-flash');
  const ExpressError = require('./utils/ExpressError');
  const methodOverride = require('method-override');
  const passport = require('passport');
  const LocalStrategy = require('passport-local');
  const User = require('./models/user')
  
  const campgroundRoutes = require('./routes/campgrounds');
  const reviewRoutes = require('./routes/reviews');
  const userRoutes = require('./routes/users');
  
  mongoose.connect(envs.MONGODB_URL, {
      useNewUrlParser: true,
      useUnifiedTopology: true
  })
  
  const db = mongoose.connection;
  db.on('error', console.error.bind(console, 'connection error:'));
  
  db.once('open', () => {
      console.log('Database Connected');
  })
  app.engine('ejs', ejsMate);
  app.set('view engine', 'ejs');
  app.set('views', path.join(__dirname, 'views'));
  
  app.use(bodyParser.json())
  app.use(express.urlencoded({ extended: true }));
  app.use(methodOverride('_method'));
  app.use(express.static(path.join(__dirname, 'public')));
  const sessionConfig = {
      secret: 'thisshouldbeabettersecret!',
      resave: false,
      saveUninitialized: true,
      cookie: {
          httpOnly: true,
          expires: Date.now() + 1000 * 60 * 60 * 24 * 7,
          maxAge: 1000 * 60 * 60 * 24 * 7
      }
  }
  app.use(session(sessionConfig));
  app.use(flash());
  
  app.use(passport.initialize({}));
  app.use(passport.session({}));
  passport.use(new LocalStrategy(User.authenticate()));
  passport.serializeUser(User.serializeUser());
  passport.deserializeUser(User.deserializeUser());
  
  app.use((req, res, next) => {
      res.locals.success = req.flash('success');
      res.locals.error = req.flash('error');
      next();
  })
  
  app.get('/fakeUser', async (req, res) => {
      const user = new User({email: 'supermario@nintendo.com', username: 'supermario'});
      const newUser = await User.register(user, 'luigi');
      res.send(newUser)
  })
  
  app.use('/', userRoutes);
  app.use('/campgrounds', campgroundRoutes)
  app.use('/campgrounds/:id/reviews', reviewRoutes)
  
  app.get('/', (req, res) => {
      res.render('home')
  })
  
  app.all('*', (req, res, next) => {
      next(new ExpressError('Page Not Found'), 404)
  })
  
  app.use((err, req, res, next) => {
      const { statusCode = 500 } = err
      if (!err.message) err.message = 'Oh No, Something Went Wrong!';
      res.status(statusCode).render('error', { err });
  })
  
  app.listen(port, () => {
      console.log(`Serving on port ${port}`);
  })