Programming node.js, php, python, java…

Menu

Lets try the new Express 4.0 version

Express is a well-known library for building simple web applications. Also express is a really modular library you can easily add other modules and middlewares to make your life easier. With the new version, the structure is more modular and the core of the code is split into multiple modules.

Getting started, as you remember the old express version had express generator built-in which is now separated to `express-generator` module. To generate application boilerplate:

Now the express should be installed with the dependencies of other libraries. The server start is hidden in `bin/www` file, run it and open browser localhost:3000. The browser page should look like this:

The changes that 4.0 bring are more like structural, all the previously included middlewares are now separated modules:

The greatest change is the Router support, which allows to create sub-routes with separated middleware stack. Read more about the router usage in Express guide router. For example, in the project you have created users routes, which contains separate router instance with authentication middleware which is applied only for this router.

If you are using the old version of express 3.5 and want to upgrade to express 4, make sure you have look through all the middleware changes. There are a lot of middlewares which might not be compatible with the new session middleware. But in overall there is not any big changes that breaks the compatibility and upgrading to newer version should be easy.