-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.ts
More file actions
41 lines (33 loc) · 862 Bytes
/
index.ts
File metadata and controls
41 lines (33 loc) · 862 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
34
35
36
37
38
39
40
//alternative import approaches...
//import http = require('http');
import * as http from 'http'
import handler from './handler'
var h = new handler("chuck the man");
console.log(h.getName());
// make a request
var options = {
port: 80,
hostname: "www.msn.com",
headers: {
"User-Agent": "Mozilla"
}
};
var req = http.request(options, (res) => {
var totalChunks = 0;
console.log(`STATUS: ${res.statusCode}`);
console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
res.setEncoding('utf8');
res.on('data', (chunk) => {
totalChunks++;
//console.log(`BODY: ${chunk}`);
});
res.on('end', () => {
console.log('No more data in response. Total Chunks: %d', totalChunks);
});
});
req.on('error', (e) => {
console.log(`problem with request: ${e.message}`);
});
// write data to request body
//req.write("foo");
req.end();