-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14_https.js
41 lines (34 loc) · 952 Bytes
/
14_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
const https = require("https")
const fs = require("fs")
const url = "https://en.wikipedia.org/wiki/India"
// any request running over https will use `443 port`
const options = {
hostname: "en.wikipedia.org",
port: 443,
path: "/wiki/India",
method: "GET"
}
const request = https.request(options, res => {
let responseBody = ""
res.setEncoding("utf-8")
res.on("data", (data) => {
console.log('---chunk', data.length)
responseBody += data
})
res.on("end", _ => {
fs.writeFile('./assets/wiki_india.html', responseBody, err => {
if(err)
throw err
console.log('wiki india file created')
})
})
})
request.end()
const request2 = https.get(url, res => {
let download = fs.createWriteStream("./assets/wiki_india_1.html")
res.pipe(download)
res.on('end', _ => {
console.log('complete request')
})
})
request2.end()