Hardi Patel
Hardi Patel

Reputation: 45

ReferenceError: res is not defined in NodeJS

My NodeJS Code. I am getting correct result in console but page is not redirected to listings page

function displayCities(cname) {
    var pageData = {
      title: "Listings",
      cities: null
    };
    axios(
      //the request
      {
        url: "https://sandbox.repliers.io/listings?city=" + cname,
        method: "GET",
        headers: {
          'Content-Type': 'application/json', 
          'REPLIERS-API-KEY': 'SKoKOGhEO42QzdkZ1cowKgLGm2mwm4'
        }
      }
    ).then(function (response){
      //on success do stuff
      console.log(response.data);
      pageData.cities = response.data; //store JSON results in pageData.cities (previously null)
      res.render("listings", pageData);
    }).catch(function (error){
      console.log(error);
    });
  }

Upvotes: 1

Views: 1015

Answers (1)

user18590948
user18590948

Reputation:

You have not passed the res object to the function.

To be able to access methods of the res object, you should add it to the function signature and give it to the function where you call it.

Upvotes: 2

Related Questions