1

I am trying to follow the example given here:

const mongoose = require("mongoose");
const session = require("express-session");
const MongoStore = require("connect-mongo")(session);

but this fails immediately with:

ServerMiddleware Error: Class constructor MongoStore cannot be invoked without 'new'

on the third line.

Is MongoStore documented somewhere? Is there a better example/tutorial I should following?

Marc
  • 1,812
  • 4
  • 23
  • 36

1 Answers1

1

That tutorial is over 2 years old which contains deprecated syntax, you can either downgrade your npm pkg versions, or use the updated syntax:

import session from 'express-session'
import MongoStore from 'connect-mongo'


const app = express();
app.use(session({
  secret: 'foo',
  store: MongoStore.create(options)
}));

Tom Slabbaert
  • 21,288
  • 10
  • 30
  • 43