I'm migrating from express 3.x
to express 4.x
I'm having issues finding a mongo session store which works with the new session
middleware.
Previously:
express 3.x
had connect
as a dependency, which in turn came with bundled session
middleware.
In order to persist sessions in a mongo database, the de-facto middleware was connect-mongo
.
New world order:
Now with express 4.x
, connect
is no longer a dependency.
As such, pretty much all the previously bundled middleware has been factored out into separate middleware, such as session
listed above.
session
takes a store
, but since connect-mongo
depends on connect
, is is not compatible with express 4.x
.
Question:
I cannot find information on which mongo session store to use when migrating to express 4.x
. Any suggestions?
connect-mongo
still works in express 4.x
, however, you now pass in session
instead of express
Express 3.x:
var express = require('express');
var mongoStore = require('connect-mongo')(express); // note parameter = express
Express 4.x:
var session = require('express-session');
var mongoStore = require('connect-mongo')(session); // note parameter = session
NPM:
Unfortunately, at the time of writing, the latest version of connect-mongo
has not been deployed to npm.
EDIT: The latest version of connect-mongo
has been deployed to npm
You can either download the latest version direct from github
or a workaround is to create a temporary object:
{
session: session
}
and pass this to mongo-connect
:
var mongoStore = require('connect-mongo')({session: session});
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