title: Weather API data request
body: <p>I have this ejs template that inputs the name of the city, the city gets stored into the database and then display the related weather result. I created a controller to POST the city from that input box. The city name gets stored easily and gets a success message but it does not pass that city to the GET request into the weather API URL to display the related weather details.</p>
  
  <p>Here is my controller for city:</p>
  
  <pre><code>const mongoose = require('mongoose');
  const axios = require('axios');
  const City = require('../models/city');
  
  exports.addCity = (req, res, next) =&gt; {
      const city = new City({
          _id: new mongoose.Types.ObjectId(),
          cityName: req.body.cityName
      });
      city
          .save()
          .then(result =&gt; {
              console.log(result);
              res.status(201).json({
                  message: "Created city successfully"
              });
          })
  
          .catch(err =&gt; {
              console.log(err);
              res.status(500).json({
                  error: err
              });
          });
  };
  
  
  exports.getCity = (req, res, next) =&gt; {
  
      City.find({}).then(docs =&gt; {
              cities: docs.map(doc =&gt; {
                  return {
                      city: doc.cityName
                  }
              })
  
              let apiKey = '**************************';
              var city = cities;
              var url= `http://api.openweathermap.org/data/2.5/weather?q=${city}&amp;appid=${apiKey}`;
              axios(url)
  
              .then( (response) =&gt; {
  
                  var cityData = response.data;
  
                  var weather = {
                      city: city,
                      temperature: Math.round(cityData.main.temp),
                      description: cityData.weather[0].description,
                      icon: cityData.weather[0].icon
                  }
  
                  // var weather_data = { weather : weather };
  
                  console.log('heyyyy', weather);
  
                  res.render('index', {
                      weather: weather
                  });
              })
              .catch( (error) =&gt; {
                  console.log(error);
              })
      })
      .catch(err =&gt; {
          console.log(err);
          res.status(500).json({
              error: err
          });
  })
  
  }
  </code></pre>
  
  <p>And here is the snippet of the ejs template:</p>
  
  <pre><code>                     &lt;article class="media"&gt;
                              &lt;div class="media-left"&gt;
                                  &lt;figure class="image is-50x50"&gt;
                                      &lt;img src="http://openweathermap.org/img/w/&lt;%= weather.icon %&gt;.png" alt="Image"&gt;
                                  &lt;/figure&gt;
                              &lt;/div&gt;
                              &lt;div class="media-content"&gt;
                                  &lt;div class="content"&gt;
                                      &lt;p&gt;
                                          &lt;span class="title"&gt;&lt;%= weather.city %&gt;&lt;/span&gt;
                                          &lt;br&gt;
                                          &lt;span class="subtitle"&gt;&lt;%= weather.temperature %&gt;&lt;/span&gt;
                                          &lt;br&gt; &lt;%= weather.description %&gt;
                                      &lt;/p&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/article&gt;
  </code></pre>
  
  <p>Whenever I run my localhost, it only creates the city into the database and display console with the lots of error data back with last two lines saying:</p>
  
  <pre><code>data: { cod: '404', message: 'city not found' } } }
  { _id: 5c6d4e18d1ad342458c3df64, cityName: 'mumbai', __v: 0 }
  </code></pre>
  
  <p>Kindly help to figure out the problem.</p>