-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.js
More file actions
46 lines (36 loc) · 957 Bytes
/
profile.js
File metadata and controls
46 lines (36 loc) · 957 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
const https = require('https')
let get = (username) =>{
// [x] connect to github API
let options = {
'hostname': 'api.github.com',
'port': 443,
'path': `/users/${username}`,
'method': 'GET',
'headers': {
'user-agent': 'nodejs'
}
}
// [x] Read the data
let request = https.request(options, (res)=>{
if (res.statusCode === 200){
let body = ''
res.on('data',(data) => {
body = body + data
})
// [x] TODO: Parse the data
res.on('end', ()=>{
let data = JSON.parse(body)
console.log(data)
})
}else{
console.log(`
Username ${username} Not Found
Error Code: , ${res.statusCode}`)
}
})
request.end()
request.on('error', (e) => {
console.error(e)
})
}
module.exports = get