Strangerliquid Strangerliquid - 5 months ago 19
Node.js Question

Node js ignoring unbundled middleware

I have some issue with middleware that is no longer budnled with NODE.js
I made just like here:

Node js Error: Most middleware (like session) is no longer bundled with Express and must be installed separately

But i still got the same error: "Most middleware bla bla bla..."

var express = require('express');
var mongoose = require('mongoose');
var path = require('path');
var bodyParser = require('body-parser');
var config = require('config');
var session = require('express-session');

var app = express();
var IS_DEV = (app.get('env') === 'development');
var MongoStore = require('connect-mongo')(express);

app.use(session({
secret: config.get('session:secret'),
key: config.get('session:key'),
cookie: config.get('session:cookie'),
store: new MongoStore({mongoose_connection: mongoose.connection})
}));


Package installed and i see it in
node_modules
folder. And i don't see any errors like:
session is undefined
What i did wrong?

Btw same going on with
express-error-handler
package



  • windows 8.1

  • node 4.4.0

  • mongodb 3.2.4

  • npm 2.14.20

  • express 4.13.4



Responce:

Error: Most middleware (like session) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.
[1] at Function.Object.defineProperty.get (C:\Work\todoapp\node_modules\express\lib\express.js:99:13)
[1] at connectMongo (C:\Work\todoapp\node_modules\connect- mongo\src\index.js:48:43)
[1] at Object.<anonymous> (C:\Work\todoapp\app.js:10:42)
[1] at Module._compile (module.js:409:26)
[1] at Object.Module._extensions..js (module.js:416:10)
[1] at Module.load (module.js:343:32)
[1] at Function.Module._load (module.js:300:12)
[1] at Module.require (module.js:353:17)
[1] at require (internal/module.js:12:17)
[1] at Object.<anonymous> (C:\Work\todoapp\bin\www:7:11)
[1] at Module._compile (module.js:409:26)
[1] at Object.Module._extensions..js (module.js:416:10)
[1] at Module.load (module.js:343:32)
[1] at Function.Module._load (module.js:300:12)
[1] at Function.Module.runMain (module.js:441:10)
[1] at startup (node.js:139:18)
[1] at node.js:968:3
[1] Program node --debug ./bin/www exited with code 1
[1]

Answer

Since you're using Express 4, the setup for connect-mongo is incorrect.

It should be:

var session = require('express-session');
...
var MongoStore = require('connect-mongo')(session);
                                          ^^^^^^^ not `express`

See the documentation.

Comments