Skip to content

Commit 53b92e8

Browse files
Update README.md
1 parent c5b5323 commit 53b92e8

1 file changed

Lines changed: 43 additions & 5 deletions

File tree

README.md

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,48 @@ Input http://localhost:4000/users/50/books/5
423423
```https://expressjs.com/en/guide/writing-middleware.html```
424424
425425
4. Middleware functions can perform the following tasks: <br />
426+
- Execute any code.
427+
- Make changes to the request and the response objects.
428+
- End the request-response cycle.
429+
- Call the next middleware in the stack.
426430
427-
-Execute any code.
428-
-Make changes to the request and the response objects.
429-
-End the request-response cycle.
430-
-Call the next middleware in the stack.
431+
>Let see the simple function for req and response with global middleware call
432+
433+
```ruby
434+
var express = require('express')
435+
var app = express()
436+
437+
var myLogger = function (req, res, next) {
438+
console.log('LOGGED')
439+
next()
440+
}
441+
442+
app.use(myLogger)
443+
app.get('/', function (req, res) {
444+
res.send('Hello World!')
445+
})
446+
447+
app.listen(3000, () => console.log("Application running on 3000 port"))
448+
449+
```
450+
451+
Simple middle ware for logging, next() function is not a part of the Node.js or Express API.
452+
but is the third argument that is passed to the middleware function.
453+
454+
```
455+
var express = require('express')
456+
var app = express()
457+
458+
var myLogger = function (req, res, next) {
459+
console.log('LOGGED')
460+
next()
461+
}
462+
```
463+
464+
To load the middleware function, call app.use(), specifying the middleware function.
465+
466+
```
467+
Calling the global
468+
```
469+
app.use(myLogger)
431470
432-
>Let see the simple function for req and response

0 commit comments

Comments
 (0)