Created
December 25, 2019 12:57
-
-
Save boudhayan-dev/08d7404074d75798fa6f786ab9ac0091 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
require('dotenv').config(); | |
const express = require("express"); | |
const path = require('path') | |
const app = express() | |
const hbs = require("hbs") | |
// auth related imports | |
const session = require('express-session'); | |
const mongoose = require('mongoose'); | |
const mongodbStore = require('connect-mongo')(session); | |
const router = require("./router/routes"); | |
const staticPath = path.join(__dirname, '../public') | |
const viewsPath = path.join(__dirname, "../templates/views") | |
const partialsPath = path.join(__dirname, "../templates/partials") | |
let PORT = process.env.PORT || 3000 | |
app.set("view engine", "hbs") | |
app.set("views", viewsPath) | |
app.use(express.static(staticPath)) | |
hbs.registerPartials(partialsPath) | |
// Accept json as well as form data | |
app.use(express.json({ limit: "5mb"})) | |
app.use(express.urlencoded({ extended: true, limit: '5mb' })) | |
// Connect to mongodb | |
mongoose.connect(process.env.DBURL, { | |
useNewUrlParser: true, | |
useCreateIndex: true | |
}); | |
//session | |
app.use(session({ | |
name: 'quicklinks.sess', store: new mongodbStore({ | |
mongooseConnection: mongoose.connection, | |
touchAfter: 24 * 3600 | |
}), secret: process.env.SECRET, resave: false, | |
saveUninitialized: false, cookie: { maxAge: 1000 * 60 * 15 } | |
})); | |
// Register the routes | |
app.use("/", router) | |
app.listen(PORT, () => { | |
console.log("Started on port " + PORT); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment