-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.js
More file actions
67 lines (58 loc) · 1.53 KB
/
demo.js
File metadata and controls
67 lines (58 loc) · 1.53 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
function Complx(add){
console.log(add(200,310));
}
//call back function.
Complx(function(a,b){
return a+b;
})
//importing from other Js file.
var imp = require('./functions');
console.log(imp(10));
var http = require('http');
var data = [
{name:"surendra",id:1920},
{name:"anonyuous",id:1835}
]
http.createServer(function(req,res){
res.writeHead(200,{'content-type':'application\json'})
res.write(JSON.stringify(data));
res.end();
}).listen(5000);
var page = `
<h1>New to this</h1>
<input type="text"/> <br></br>
<input type="text"/>
`
http.createServer(function(req,res){
res.writeHead(200,{'content-type':'application\html'})
res.write(page);
res.end();
}).listen(4200);
//npm package upper case(to install: npm i upper-case)
var uc = require('upper-case');
http.createServer(function(req,res){
res.write(uc.upperCase('Node web page changes using nodemon'));
res.end();
}).listen(3000);
//Read file
var fs = require('fs');
http.createServer(function(req,res){
fs.readFile('demo.html',function(err,data){
res.writeHead(200,{'content-type':'text/html'});
res.write(data);
res.end();
})
}).listen(3200);
//events(Ex:here it is "open" event)
var rs = fs.createReadStream('./demo.html');
rs.on('open',function(){
console.log('File is open');
})
//create custom event
var events = require('events');
var eventEmitter = new events.EventEmitter();
//make custum event speak
eventEmitter.on("speak",function(name){
console.log(name,'is speaking');
})
eventEmitter.emit("speak","surendra");