In pre-ES6, this is how I import connect-mongo (session):
var MongoStore = require("connect-mongo")(session);
But how can I import it in ES6?
import MongoStore from 'connect-mongo';
let monStore = MongoStore(session);
Error:
const Store = connect.Store || connect.session.Store;
^
TypeError: Cannot read property 'Store' of undefined
Any ideas?
With connect-mongodb-session which is pretty similar, you can:
import { default as connectMongoDBSession} from 'connect-mongodb-session';
const MongoDBStore = connectMongoDBSession(session);
var store = new MongoDBStore({
uri: 'mongodb://localhost:27017/tmp',
collection: 'sessions'
});
Both packages (connect-mongodb-session and connect-mongo) are exporting an anonymous function that takes the express-session module as an argument. This function returns a constructor and is exported with modules.export, therefore it's considered a default export and you can import it with import { default as NameForAnonymousFunction } from 'connect-mongo'.
Now, I think that a good learning practice you should follow is to try to read the actual code of packages you are installing, at least the index.js.
Since connect-mongo is using [email protected] and connect-mongodb-session is using [email protected], i've added a deprecated tag before connect-mongo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With