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
}));