Here is my code:
const express = require('express')
const app = express()
let counter = 0
app.use((req, res, next) => {
counter ++
console.log(counter + ' request fulfilled');
console.log(req.url)
next()
})
app.get('/check1', (req, res) => {
res.send('Got a new request')
})
app.get('/check', (req, res) => {
res.send('You got back')
})
app.listen(3000, () => {
console.log('Listening on port 3000');
})
I am just learning, so it might be silly question, but I do not understand, why if I am going from “localhost:3000/check” to “localhost:3000/chec”(non-existing route) my app.use() counts it as 2 requests?
Here is my console output with surfing the routes:
PS E:CodeStuding 004 Server-Express> node .index.js
Listening on port 3000
1 request fulfilled
/check
2 request fulfilled
/check1
3 request fulfilled
/check
4 request fulfilled
/chec
5 request fulfilled
/chec
As you can see /chec request was called twice, eventhough I moved to the URL once.