Created
December 3, 2021 19:01
-
-
Save goish135/4fc38a7732c8a8747fb26daddd25a06a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const app = express(); | |
const mongoose = require("mongoose"); | |
const bodyParser = require("body-parser"); | |
const session = require("express-session"); | |
const flash = require("connect-flash"); | |
const moment = require("moment"); | |
const seedDB = require("./seed"); | |
const removeUsers = require("./remove"); | |
const routes = require("./routes/index"); | |
// const generatePDF = require('./generatePdf'); | |
require('dotenv').config({path:'variables.env'}); | |
mongoose.Promise = global.Promise; //tell mongoose to use ES6 promises | |
mongoose.connect('mongodb://localhost:27017/', err => { | |
if (err) { | |
console.log("Cannot connect to database"); | |
console.log(err); | |
} else { | |
console.log("Connection to database was succesful"); | |
} | |
}); | |
const User = require("./models/user"); | |
app.set("view engine", "ejs"); | |
app.set("views", `${__dirname}/views`); | |
app.use(bodyParser.urlencoded({ extended: true })); | |
app.use(bodyParser.json()); | |
app.use(express.static(`${__dirname}/public`)); | |
app.use( | |
session({ | |
secret: process.env.SECRET, | |
resave: false, | |
saveUninitialized: false | |
}) | |
); | |
app.use(flash()); | |
app.use((req, res, next) => { | |
res.locals.error = req.flash("error"); | |
res.locals.success = req.flash("success"); | |
res.locals.moment = moment; | |
next(); | |
}); | |
//ROUTES | |
app.use(routes); | |
// removeUsers(); | |
// seedDB(); | |
app.listen("3000", () => { | |
console.log("Server is up and running"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment