-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.js
More file actions
33 lines (23 loc) · 753 Bytes
/
Server.js
File metadata and controls
33 lines (23 loc) · 753 Bytes
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
var http = require('http');
var events = require('events');
var eventEmitter = new events.EventEmitter();
//code for creating the server in node js
var server = http.createServer(function(req,res){
//Event triggeer
eventEmitter.emit('someone requested','Test');
res.end("server works!!!");
});
//event listner
eventEmitter.on('someone requsted',function(){
console.log('a request has been done on the server !!',data)
});
/*
listen method have to arguments
/first one is port number
second is the host name
default name is local host
but we can give our name if we need to do it
*/
server.listen(3000,'localhost',function(){
console.log("server stared on port no : 3000");
});