Application Programming Interface (API) Problem:

I work with js node, express, request and ejs. The following code works, but the JSON data is not updated. If I browse the raw JSON URL, I do not get the same data as displayed in my request.

app.js file :

var express = required (express) ;
var app = express() ;
var application = required (application) ;

app.set(view engine, ejs) ;
app.use(express.static(__dirname + /public)) ;

app.get(/, function(req, res){const weatherURL = + apiId + &client_secret= + apiSecret;request(weatherURL, function(error, response, body){let weather_json = JSON.parse(body);const weather = {forecast: weather_json.response[0].periods[0].weather,temp: weather_json.response[0].periods[0].feelslikeF,icon: weather_json.response[0].periods[0].icon};res.render(index, { again: weather}))

app.listen(process.env.PORT, process.env.IP, function(){
console.log(App started!);
}) ;

I get a partly cloudy sky with isolated thunderstorms at 65° in my application when the data should show a partly cloudy sky at 62°.

Maybe JSON’s stuck in the cache?

JSON from the url:

Success:true,error:null,response:-83,814,lat:35.341},interval:daynight,periods:[{timestamp:1538650800,validTime:2018-10-04T07:00:00-04:00,dateTimeISO:2018-10-04T07:00:00-04:00,maxTempC:29,maxTempF:85,minTempC:null,minTempF:null,avgTempC:25, avgTempF:77, tempC:null, tempF:null, pop:7, precipMM:0, precipIN:0, iceaccumumMM:0, iceaccumIN:0, maxHumidity:92, minHumidity:60, humidity:70, uvi:7, pressureMB:1019, pressureIN:30.09,sky:43,snowCM:0,snowIN:0,feelslikeC:17,feelslikeF:62,minFeelslikeC:17,minFeelslikeF:62,maxFeelslikeC:31,maxFeelslikeF:88,avgFeelslikeC:26,avgFeelslikeF :79,dewpointC:17,dewpointF:62,maxDewpointC:20,maxDewpointF:68,minDewpointC:17,minDewpointF:62,avgDewpointC:19,avgDewpointF:66,windDirDEG:150,windDirDir :SSE, windDirMaxDEG: 290, windDirMax: WNW, windDirMinDEG: 280, windDirMin: W, windGustKTS:6, windGustKPH:11, windGustMPH:7, windSpeedKTS:2, windSpeedKPH:4, windSpeedMPH:3, windSpeedMaxKTS: 4, windSpeedMaxKPH:8, windSpeedMaxMPH:5, windSpeedMinKTS:1, windSpeedMinKPH:2, windSpeedMinMPH:1, windDir80mDEG:224, windDir80m: SW,windDirMax80mDEG : 290,windDirMax80m : WNW,windDirMin80mDEG : 280,windDirMin80m : W,windGust80mKTS:5,windGust80mKPH:8,windGust80mMPH:5,windSpeed80mKTS:4,windSpeed80mKPH:7,windSpeed80mMPH:4,windSpeedMax80mKTS:5,windSpeedMax80mKPH: 8,windSpeedMax80mMPH:5,windSpeedMin80mKTS:2,windSpeedMin80mKPH:3,windSpeedMin80mMPH:2,weather:partly cloudy,weatherCoded: [{time stamp:1538650800,wx:PA::F,dateTimeISO:2018-10-04T07:00-04:00}],weatherPrimary:partly cloudy,weatherPrimaryCode::SC,cloudsCoded:SC,icon:cloudy.png,isDay:true}],profile:{tz:America/New_York}]}.

How do you solve the API problem?

Solution 1:

If you think the data is cached, try adding a time stamp to the query parameters. Something like this:

const weatherURL = + apiId + &client_secret= + apiSecret + &t= + ;

Solution 2:

I’m trying to reproduce your problem, but I haven’t been able to find a match between the raw json and the data displayed in the views.

Node js express request weather API –

Could it have something to do with the ejs cache, have you tried adding this line?

app.disable (view the cache) ;

Good luck!

weather app using node js,node js weather-app github,node js website example,express js,node js sample project download,building a website with node js and express,google weather api javascript,javascript weather app tutorial,weather-js,php weather api,build a simple weather app,how to make a weather app using api,weather forecast javascript,weather api tutorial,openweathermap api,npm weather api

You May Also Like

Effectiveness of telephony services with VoIP technology

Technology has fundamentally changed the whole sector, and the communications sector is…

Swipe Back like Pinterest or Tumblr –

Development issue/problem: Does anyone know how Pinterest or Tumblr used the swipe…

Dell Latitude 7210 2-in-1 (2020): Specs – Detailed Specifications

Latitude delta 7210 2-in-1 AvailabilitySupplied2020Storage Screen size 12.3 inchesInformation The size: 12.3”…

How to get Latest MXQ Pro 4k Firmware? (Easy Guide 2021)

For upgrading to MXQ Pro 4k firmware, it can be a streaming…