-
Notifications
You must be signed in to change notification settings - Fork 0
/
12-https.js
140 lines (94 loc) · 2.7 KB
/
12-https.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
const { copyFile } = require('fs');
const http=require('http');
const server=http.createServer((req,res)=>{
if(req.url === '/'){
// res.write('welecome to our home page');
res.end('welecome to our home page');
}
else if(req.url=='/about'){
res.end('Here is our short history');
}
else{
res.end(`
<h1>Ooops!</h1>
<p>We can not seem to find the page you are looking for</p>
<a href="/">back Home</a>
`)
}
});
server.listen(5000);
//---------os-------------
// const os=require('os');
// const user=os.userInfo();
// // console.log(user);
// // console.log(`uptime is ${os.uptime()}`);
// const currenOs={
// name:os.type(),
// release:os.release(),
// totalMem:os.totalmem(),
// freeMem:os.freemem(),
// }
// console.log(currenOs);
// const http=require('http')
// const server=http.createServer((req,res)=>{
// if(req.url === '/'){
// res.write('Hello world');
// res.end();
// }
// if(req.url ==='/api/courses'){
// res.write(JSON.stringify([1,2,3]));
// res.end();
// }
// });
// server.on('connection',(socket)=>{
// console.log('New connection')
// })
// server.listen(3000);
// console.log('Listening on port 3000...');
//-------------------events-----------
//------------------------------------
// const EventEmitter = require('events');
// const emitter=new EventEmitter();
//Register a listener
// emitter.on('messageLogged',function(){
// console.log("Listener called");
// });
// const Logger = require('./logger');
// const logger=new Logger();
// //Register a listener
// logger.on('messageLogged',(arg)=>{
// console.log("Listener called: ",arg);
// });
// logger.log('message');
// const log = require('./logger');
// console.log('message');
//Making a noise ,produce signoling
//Raise event
// emitter.emit('messageLogged');
//using many emmitters,events
// emitter.emit('messageLogged',{id:1, url:'http://'});
//filesystem with sync
// const fs=require('fs')
// fs.readdirSync('./');
// const files = fs.readdirSync('./');
// console.log(files);
// fs.readdir('./',function(err,files){
// if(err) console.log('Error',err);
// else console.log('Result',files);
// });
//find filesystem
// const os= require('os');
// var totalMemory=os.totalmem()
// var freeMemory=os.freemem();
// console.log('Total Memory: '+totalMemory);
// //template string
// //ES6/ES2015:ECMAScript 6
// console.log(`Total Memory:${totalMemory}`)
// console.log(`Total Memory:${freeMemory}`)
//find filename
// const path=require('path');
// var pathObj=path.parse(__filename);
// console.log(pathObj);
// const log=require('./logger');
// // logger=1;
// log('message');