-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFirstPracticePage.js
135 lines (68 loc) · 2.21 KB
/
FirstPracticePage.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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
var http = require('http')
http.createServer(function (req,res){
res.writeHead(200,{'set-type':'test/type'})
res.end('Hello World')
}).listen(8080)
///Practce - 2
var http = require('http')
http.createServer(function (req, res){
res.writeHead(200,{'Content-Type':'text/html'});
res.end("Hello World");
}).listen(8080);
///Practice - 3
var http = require('https')
http.createServer(function(req,res){
res.writeHead(200,{'Content-type':'text/html'});
res.end('Hello world')
}).listen(8080)
/// Practice - 4
var http = require('http')
http.createServer(function(req,res){
res.writeHead(200,{'Content-type':'text/html'});
res.end('Hello world')
}).listen(3000)
/// Points to be noted :
/// Node js is an open source, Java Script runtime
/// which is asynchronous and singlethreaded platform
/// now , in a PHP :
/// 1) It will take the request
/// 2) It will send the request to the computer
/// 3) It will wait for the computer to read the file
/// 4) recieves the response
/// 5) sends back to the UI
/// 6) Gets ready to take another requesst
/// But Node JS doesn't wait for the computer to respond.
/// While the computer is reading the file, it will be ready for the next request
/// That is the advantage of Node JS.
/// file --------
/// module.js
exports.myDate = function(){
return Date();
};
/// mainModule.js
var http = require('http')
var dt = require('./module')
http.createServer(function(req,res){
res.writeHead(200,{'Content-type':'text/html'})
res.write('This is the time and date : '+ dt.myDate())
res.end();
}).listen(3000);
/// Practice - 2
//// file module.js
exports.myTime = function(){
return Date();
}
var http = require('http')
var dt = require('./module')
http.createServer(function (req,res){
res.writeHead(200,{'Content-type':'text/html'});
res.write("This is today's date"+dt.myTime)
res.end("Hello world")
}).listen(3000)
var http = require('http')
var url = require('url')
http.createServer(function(req,res){
res.writeHead(200,{'Content-type':'text/html'});
res.write(req.url);
res.end();
}).listen(3000);