Hi,
I was working on the Ravenous project earlier and was able to follow all the steps and get everything to work. However, I couldn’t figure out a way to test out individual files. For example, for the Yelp.js file, I added a console.log statement to print the output of the API request, and to run the file independently, in the console on VS Code i tried to do “node Yelp.js”, and go the error below. I believe this has to do with the fact that the file is in ES6 syntax and when I do "node " it doesn’t understand that syntax (where as when I do “npm start” it understands it). How can I test individual files in VS Code? Thanks!
“node:9035) UnhandledPromiseRejectionWarning: FetchError: invalid json response body at https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?term=resturant&location=san%20francisco&sort_by=best_match reason: Unexpected token M in JSON at position 0”
const apiKey = 'EfwEVxdzIK-yaDsoet2TbxJqvG7L3lQmRMKRkbkZFGS5KrXTx_0p5Q7bvOZPhyhFx1r38waWktyC7nDd-xNxSeJx3tce1CDuvAmjvhUraKrNnsPUmDh0lACYWHC8tXYx';
const fetch = require("node-fetch");
const Yelp = {
search(term, location, sortBy) {
return fetch(`https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?term=${term}&location=${location}&sort_by=${sortBy}`, {
headers: {
Authorization: `Bearer ${apiKey}`
}
}).then(response => {
return response.json();
}).then(jsonResponse => {
if (jsonResponse.businesses) {
return jsonResponse.businesses.map(business => ({
id: business.id,
imageSrc: business.image_url,
name: business.name,
address: business.location.address1,
city: business.location.city,
state: business.location.state,
zipCode: business.location.zip_code,
category: business.categories[0].title,
rating: business.rating,
reviewCount: business.review_count
}));
}
});
}
};
Yelp.search('restaurant', 'san francisco', 'best_match')