I'm just starting to delve into Api's via a course and essentially I am trying to pull in data from the open weather api for London. It's working IF i manually request it to console log the response via terminal (I'm on MAC) but not doing so automatically, even though it's referenced in the code. I'll paste my code below but remove my api key for obvious reasons.
Any help would be appreciated, thanks in advance for your time.
const express = require('express');
const https = require('https');
const app = express();
const port = 3000;
const url = 'https://api.openweathermap.org/data/2.5/weather?q=London&appid=12345mykeyexample';
//set route as index.html
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
//get api url and console log response
https.get(url, function(response){
console.log(response);
});
res.send('server is up and running bro');
});
// listen on port 3000
app.listen(port, () => {
console.log(`Server started bro http://localhost:${port}`);
});