/index.html
GET /index.html HTTP/1.1
Option: Value
<blank line>
<body input data>
<blank line>
HTTP/1.1 200 OK
Option: Value
<blank line>
<web page data>
<blank line>
var data = "This is a test";
var encoded = btoa(data);
var decoded = atob(encoded); // === data
const https = require('https');
https.get('https://api.weatherusa.net/v1/obs?station_id=KLOM', (resp) => {
let data = '';
resp.on('data', (chunk) => {
data += chunk;
});
resp.on('end', () => {
const respobj = JSON.parse(data);
console.log(data);
console.log("Weather at " + respobj[0].station_id);
console.log("Sky: " + respobj[0].sky);
console.log("Temperature: " + respobj[0].t_f);
var sunset = new Date(0);
sunset.setUTCSeconds(respobj[0].sunset_t);
console.log("Sunset time: " + sunset);
});
}).on('error', (e) => {
console.log(e.message);
});
httpclient.js
and run with: node httpclient.js
[{"station_id":"KLOM","stname":"Wings Field","net":"METAR","lat":"40.1399993896"
,"lon":"-75.2699966431","elev":"92","cond":"","sky":"CLR","obstime":"37 minutes
ago (2020\/08\/31 11:35:00 EDT)","obstime_t":"1598888100","t_f":71,"td_f":61,"p_
hpa":1019,"p_in":"30.08","precip":null,"snow_depth":null,"wspeed_mph":6,"wgust_m
ph":null,"wdir_compass":"ENE","hum":"72%","chill":74,"feelslike":74,"sunrise_t":
1598869664,"sunset_t":1598916852,"night":false,"wx_icon":"clear","wx_str":"Clear
"}]
Weather at KLOM
Sky: CLR
Temperature: 71
Sunset time: Mon Aug 31 2020 19:34:12 GMT-0400 (Eastern Daylight Time)