forked from balwantjassal/practical-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_old.js
34 lines (31 loc) · 899 Bytes
/
index_old.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var http=require("http");
var events=require("events");
var server=http.createServer(function(req,res){
if(req.url=="/"){
res.writeHead(200,{'content-type':'text/json'});
res.write("{'CourseName':'NodeJS','Code':'INT222'}");
res.end();
}
if(req.url=="/student"){
res.write("This is STUDENT Web page");
res.end();
}
if(req.url=="/employee"){
res.write("This is Employee Web page");
res.end();
}
});
server.listen(5000,(err,data)=>{
if(err) throw err;
console.log("Server Connected at Port 5000");
});
var eventEmitter=new events.EventEmitter();
var connectionHandler=function(){
console.log("Connection Successfull with Connection Event");
eventEmitter.emit("data_received");
};
eventEmitter.on("connection",connectionHandler);
eventEmitter.on("data_received",()=>{
console.log("My Data ");
});
eventEmitter.emit("connection");