I'm completely stumped on what's causing the issue in my code.
This error message keeps popping up:
TypeError: Class constructor MongoStore cannot be invoked without 'new'
Does anyone have any insights into this problem? And is there a solution available?
I've spent hours trying to identify my mistake with no luck.
require('dotenv').config()
const express = require('express')
const app = express()
const mongoose = require('mongoose')
mongoose.connect(process.env.CONNECTIONSTRING, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => {
app.emit('pronto')
})
.catch(e => console.log(e))
const session = require('express-session')
const MongoStore = require('connect-mongo')(session)
const routes = require('./routes')
const path = require('path')
const { middleGlobal } = require('./src/middlewares/middleware')
app.use(express.urlencoded({ extended: true }))
app.use(express.static(path.resolve(__dirname, 'public')))
const sessionOptions = session({
secret: 'hdfkajdkk58fj',
store: new MongoStore({ mongooseConnection: mongoose.connection }),
resave: false,
saveUninitialized: false,
cookie: {
maxAge: 1000 * 60 * 60 * 24 * 7,
httpOnly: true
}
})
app.use(sessionOptions)
app.use(flash())
app.set('views', path.resolve(__dirname, 'src', 'views'))
app.set('view engine', 'ejs')
// Our custom middleware
app.use(middleGlobal)
app.use(routes)
app.on('pronto', () => {
app.listen(3000, () => {
console.log("Server is running on port 3000")
console.log("Visit http://localhost:3000")
})
})