server.js
//then generates array of "Weather" objects to send to front end
then generates array of "Weather" objects to send to front end
then generates array of " Weather " objects to send to front end
function weatherApp(req, res) {
  const darkSkyUrl = `https://api.darksky.net/forecast/${process.env.WEATHER_API_KEY}/${req.query.data.latitude},${req.query.data.longitude}`;
  return superagent.get(darkSkyUrl)
    .then(result => {
      const weatherSummaries = result.body.daily.data.map(day => new Weather(day));
      weatherSummaries.forEach(item => {
        let insertStatement = 'INSERT INTO weather ( time, forecast, search_query, created_at ) VALUES ( $1, $2, $3, $4);';
        let insertValues = [item.time, item.forecast, req.query.data.search_query, item.created_at];
        client.query(insertStatement, insertValues);
      })
      res.send(weatherSummaries);
    })
    .catch(error => handleError(error, res));
}
function weatherApp ( req , res ) { const darkSkyUrl = ` ${ process . env . WEATHER_API_KEY } ${ req . query . data . latitude } ${ req . query . data . longitude } ` ; return superagent . get ( darkSkyUrl ) . then ( result => { const weatherSummaries = result . body . daily . data . map ( day => new Weather ( day ) ) ; weatherSummaries . forEach ( item => { let insertStatement = 'INSERT INTO weather ( time, forecast, search_query, created_at ) VALUES ( $1, $2, $3, $4);' ; let insertValues = [ item . time , item . forecast , req . query . data . search_query , item . created_at ] ; client . query ( insertStatement , insertValues ) ; } ) res . send ( weatherSummaries ) ; } ) . catch ( error => handleError ( error , res ) ) ; }
then generates array of "Weather" objects to send to front end
then generates array of " Weather " objects to send to front end
//make map one liner