-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58e7902
commit ebadd1e
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//counting how many times the API is called using EventEmmiter | ||
|
||
const express = require('express'); | ||
const EventEmitter = require('events'); | ||
const app = express(); | ||
const event = new EventEmitter(); | ||
let count =0; | ||
|
||
|
||
app.get('/' , (req , res)=>{ | ||
res.send('api called'); | ||
event.emit("countAPI"); //generating/triggering an event having name "countAPI" | ||
}); | ||
|
||
app.get('/search' , (req , res)=>{ | ||
res.send('search api called'); | ||
event.emit("countAPI"); | ||
}); | ||
|
||
app.get('/update' , (req , res)=>{ | ||
res.send('update api called'); | ||
event.emit("countAPI"); | ||
}); | ||
|
||
//handelling the generated event | ||
event.on("countAPI" , ()=>{ | ||
count++; | ||
console.log("event called" , count); | ||
}) | ||
|
||
|
||
app.listen(8000); |