Be the first user to complete this post

  • 0
Add to List

Understanding routers in express 4.0 - Visually

Routing in express 4.0 is much more intuitive and cleaner. We decided to put together a simple visualization of the steps involved in creating expressjs routers and route handlers 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 concepts involved are pretty simple. Express lets you spawn routers using the Router() constructor (as seen in step 1). Think of each router as a place where you can specify handlers for a collection of sub-urls. These handlers may be for any of the HTTP methods. (as seen in step 2). Once you have specified the handlers you need, simply associate the router with a base-url, which is most likely to be relative to the root ( as seen in step 3). At runtime, express combines the base-url and the sub-url to determine the appropriate route handling function.

Also Read:

  1. Configure The 'script' tag In package.json To Run Multiple Commands
  2. Configuring jshint as a pre-commit hook for your nodejs applications
  3. Find the environment variables of a nodejs process in linux
  4. What is npm shrinkwrap and when is it needed
  5. Understanding nodejs module exports and require
  6. Testing promise sequence using mocha, chai, chai-as-promised, sinon
  7. Error: can not find module 'underscore'
  8. gzip compress and cache api response in express