How to do it...

  1. Create a new file named router-level.js
  2. Initialize a new ExpressJS application and define a router:
      const express = require('express') 
      const app = express() 
      const router = express.Router() 
  1. Define our logger middleware function:
      router.use((request, response, next) => { 
          console.log('URL:', request.originalUrl) 
          next() 
      }) 
  1. Mount the Router to the path "/router"
      app.use('/router', router) 
  1. Listen on port 1337 for new connections:
     app.listen( 
         1337, 
       () => console.log('Web Server running on port 1337'), 
    ) 
  1. Save the file
  2. Open a terminal and run:
      node router-level.js
  1. In your web browser navigate to:
 http://localhost:1337/router/example
  1. The Terminal should display:
      URL: /router/example
  1. After, in your web browser, navigate to:
      http://localhost:1337/example
  1. No logs should be displayed in terminal