How to use Connect-mongo in Express 4

Source: Internet
Author: User

Following the tutorial steps above, after installing in the Session Support section, connect-mongo add:

Var Mongostore =Require(' Connect-mongo 'expressvar settings = Require ( /settings ' );  and app. (express. Cookieparserapp. (express. Session ({ //...)  })        

Then run the error:

Error: Most middleware (like session) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware. 

Ask what to do with this middleware in Express 4:

var connect = require (' Connect ');

var session = require (' express-session ');

var Mongostore = require (' Connect-mongo ') (connect);

App.use (Session ({Secret:settings.cookieSecret, store:new mongostore ({db:settings.db})});

I'll be OK with this.

Note : Express 4 is very different from before. For example, Express.session and Express.cookieparser are no longer present. Express and middleware have been stripped apart, except for the express.static.

How to use Connect-mongo in Express 4

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.