Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Migrate to Express 4


    Express 4 is almost ready for release. The previous lessons looked at Express 3, but will use Express 4 going forward. This lesson will explain some of the main breaking changes.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    Man: Express 4 is starting to reach the release candidate phases. Let's migrate to Express 4 now so that we can focus on that moving forward.

    I'll "npm express install express@4.00RC3" to grab the third release candidate, the latest as of today. When I try and run this, we'll get some good errors telling us what's going on.

    Middleware is no longer bundled. What that means is that this, where the JSON body parser stuff was bundled before, is no longer bundled. That means we will need to "npm install body-parser." We will need to require body-parser, and then, where we used this middleware before, we'll replace that with body-parser and invoke it.

    Now, if we run this, everything is up and running. Looks like everything is working fine.

    The other major feature to talk about that we've covered so far is that instead of using get and post on this people route and defining it twice, I can instead say app.route and then call get and post on that, because app.route now returns a router.

    We'll format that and delete this, delete the string. This now, if I rerun, will work just fine as well. This wouldn't have worked before. It's a new feature we're calling app.route. Passing it a string will let you chain these together -- get, post, and whatnot.

    There are some other things that have changed. App.router is removed and app.configure is removed. But we never got to that stuff, so I'm not going to worry about it here. We're simply going to focus on what Express 4 does provide moving forward.

    Lastly, there is a migration guide on Express's GitHub page. Head over to this link if you're curious about what other minor things have changed for this release.