1

currently following a tutorial from the man Brad Traversy about coding an interactive WebApp with node.js and I've run into a problem, that still consists when I paste his github code btw.

const MongoStore = require("connect-mongo")(session)

I'm using connect-mongo to store session data, but the require just doesn't work and it throws this error:

TypeError: Class constructor MongoStore cannot be invoked without 'new'

could someone help me with a brief explanation and a block of code to fix this, because I've looked through several similar questions on stackoverflow, but didn't really understand it.

Cheers

Henrik
  • 13
  • 1
  • 3

1 Answers1

0

The tutorial can be old. The library API can be changed, I recommend you to use latest docs from https://www.npmjs.com/package/connect-mongo

Also if you can find it, you can install the same version of the connect-mongo used in the tutorial with npm i connect-mongo@versionhere

new usage:

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

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

and instead of new MongoStore(), seems you need to use MongoStore.create(options)

srknzl
  • 776
  • 5
  • 13