1const https = require('https')
2
3const data = JSON.stringify({
4 todo: 'Buy the milk'
5})
6
7const options = {
8 hostname: 'whatever.com',
9 port: 443,
10 path: '/todos',
11 method: 'POST',
12 headers: {
13 'Content-Type': 'application/json',
14 'Content-Length': data.length
15 }
16}
17
18const req = https.request(options, res => {
19 console.log(`statusCode: ${res.statusCode}`)
20
21 res.on('data', d => {
22 process.stdout.write(d)
23 })
24})
25
26req.on('error', error => {
27 console.error(error)
28})
29
30req.write(data)
31req.end()