Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Share On Stumbleupon
Contact us
Hide Buttons

Understanding routers in express 4.0 — Visually

Rout­ing in express 4.0 is much more intu­itive and cleaner. We decided to put together a sim­ple visu­al­iza­tion of the steps involved in cre­at­ing expressjs routers and route han­dlers to help you get started.

routers in express 4.0

Of course, this assumes that you have already installed express 4.0 in your application.

The con­cepts involved are pretty simple.

Express lets you spawn routers using the Router() con­struc­tor (as seen in step 1). Think of each router as a place where you can spec­ify han­dlers for a col­lec­tion of sub-urls. These han­dlers may be for any of the HTTP meth­ods. (as seen in step 2).

Once you have spec­i­fied the han­dlers you need, sim­ply asso­ciate the router with a base-url, which is most likely to be rel­a­tive to the root ( as seen in step 3).

At run­time, express com­bines the base-url and the sub-url to deter­mine the appro­pri­ate route han­dling function.

Ryan Sukale

Ryan is a UX engineer living in San Francisco, California.

You may also like...

  • tuto­ri­al­hori­zon

    You’re right! Bad case of copy paste error on my part. Thanks for point­ing it out.