What’s new in Express 4

Express js has proven itself as the go to server framework for Node js. The community around Express has grown and is being used everywhere. If you haven’t noticed,  Express just released version 4 a few days ago with some exciting changes. Somethings are gone and there are some much needed and lovely additions to this already robust framework. 

So what’s out? Express no longer has Connect as a dependency. That means all of the middleware that you have come to love and rely on must be separately installed into your project. Just an extra step to get things started is all, check out the list of all the middleware that is no longer part of Express. The only one that remains is express.static().

Now, onto the good stuff. Express has added some pretty neat functionality around how it allows us to use the router. First, you can now return an instance of a single route which will allow you to attach functionality to any HTTP VERB for that route.

This helps prevent typos when generating controllers for your routes and to keep your code DRY. You can also set route specific middleware using the .all() and calling next(). Pretty awesome! Next up is the new express.Router(). Express refers to this as a ‘mini app’ where a router is just an isolation of middleware and routing. Let’s take a look.

There is much going on here, but it’s all pretty easy to wrap your head around. Like I said before, you can think of the Router as just being a mini app that has its own middleware and routing. It has some of the same functionality that your original app would. These are welcomed additions to Express and will allow one to easily organize and structure their code in a very maintainable way. These are just some of the major changes in Express 4, there are some smaller tweaks to go look at as well. So if you’re converting from Express 3 to 4, then all you would need to do is independently acquire the middleware you are using, and also not use app.configuration() , for it is now non existent. That’s all you would need to make the switch and start using all the new stuff.

2 Comments What’s new in Express 4

  1. Pingback: sac hermes

Chat here!