Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 959 of the free egghead.io lessons, plus get Node.js content delivered directly to your inbox!



Existing egghead members will not see this. Sign in.

Migrate to Express 4

1:58 Node.js lesson by

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.

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

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.

Avatar
Julian

If you are getting a "body-parser deprecated" message.

Replace: app.use(bodyParser());

With: app.use(bodyParser.urlencoded({extended: true}));

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.0.0-RC3" 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.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?