-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest-server.js
55 lines (48 loc) · 1.32 KB
/
test-server.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
var http = require('http');
var basic = require('./basic');
var singleton = require('./singleton');
var objNo = require('./obj-no-instance');
var obj = require('./obj-instance');
var objVersion2 = require('./obj-instance').ObjInstance;
http.createServer(function (req, res) {
var index = 0;
var intervalId = setInterval(function(){
if (index == 0){
console.log('basic');
basic.foo();
basic.bar();
}
else if (index == 1){
console.log('\nstatic');
singleton.foo();
singleton.bar();
}
else if (index == 2){
console.log('\nobject no instance');
var newObj = new objNo();
newObj.foo();
newObj.bar();
}
else if (index == 3){
console.log('\nobject instanciated');
obj.foo();
obj.bar();
}
else if (index == 4){
console.log('\nobject instanciated - 2nd version');
console.log('alternative - constructor exported');
var newObj = new objVersion2();
newObj.foo();
newObj.bar();
}
else {
console.log('\nthank you... ending process');
clearInterval(intervalId);
process.exit(0);
}
index++;
},3000);
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Done\n');
}).listen(3000, "127.0.0.1");
console.log('Server running at http://127.0.0.1:3000/');