Differences between express4.2.0 and express3.x operations

Source: Internet
Author: User
There are two differences: application startup: both use package. config configuration to start the app. jsExpress3 .. x is through nodeapp. js starts the application package. the config file is as follows: Express4.2 is through npmstart through node. binwww starts the application package. config file:

There are two differences: application startup: both use package. config configuration to start the app. js Express3 .. x is through nodeapp. js starts the application package. the config file is as follows: Express4.2 is through npmstart through node. /bin/www start the application package. config file:

Two differences

Difference 1: application startup:

All are configured through package. config to start app. js

Express3. x is used to start the application through node app. js

The package. config file is as follows:

Express4.2 uses npm start to start the application through node./bin/www

The package. config file is as follows:

Difference 2

Most of the middleware in the new version is not bundled with express and must be installed separately. This is the case with the session used in this example.

The solution is to install the express-session module. In my example, because the MongoDb database is used, you also need to install the session-mongoose module (not a middleware, which is equivalent to an interface with the database ).

Npm install express-session

The installation is successful and then applied in the app. js File

// Introduce the corresponding module

Var connect = require ('connect ');

Var session = require ('express-session ')

Var SessionStore = require ("session-mongoose") (connect );

Var store = new SessionStore ({

Url: "mongodb: // localhost/session ",

Interval: 120000 });

// Application

App. use (session ({

Secret: 'blog. huo. me ',

Store: store,

Cookie: {maxAge: 900000} // expire session in 15 min or 900 seconds

}));

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.