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