New features of EXPRESSJS 4.0

Source: Internet
Author: User

Expressjs is the NODEJS Web development Framework, the latest version is 4.0 compared to the 3.x version, the Expressjs 4.X version made some of the following changes:

1. To remove middleware bindings, the use of all middleware must be downloaded separately and then loaded, so the benefits of the design is that users can download the middleware and updates needed for the project on demand as needed.

var app = Express (); // 3.X version, use of middleware App.use (Express.bodyparser ()); App.use (Express.cookieparser ()); // version 4.0, middleware needs to be loaded separately var cookieparser = require (' Cookie-parser '); var bodyparser = require (' Body-parser '); //  Use App.use (Cookieparser ()); App.use (Bodyparser ()):

2.app.configure () is not in a valid, environment-based parameter configuration as long as it is configured through a simple IF-ELSE statement block, such as a development environment:

// Expressjs 3.xapp.configure (' development '  function({    // to do })); // EXPRESSJS 4.0 var env = Process.env.NODE_ENV | | ' Development ' ; if (' development ' = = env)    {//to do};

3. Changes in routing.

The processing of Expressjs 3.x routes is generally:

App.get ('/'  function(res,  res, next) {    //  todo}); App.post (  function(res  , res, next) {});

Expressjs4.0 adds a number of alternative ways to routing, such as through the app. Router instances

var app = Express (); var router = Express. Router (); Router.get (function(req, res) {..}); Router.post ('/users ',function(req,res) {...}); // call route, you can specify the root directory app.use ('/'  , router);

More reference http://scotch.io/bar-talk/expressjs-4-0-new-features-and-upgrading-from-3-0

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.