christophebe / serp

Google Search SERP Scraper
101 stars 24 forks source link

triggeruncaughtexception #20

Open adnanhassan23 opened 2 years ago

adnanhassan23 commented 2 years ago

I'm extremely newbie at Node js. When I run this the code async function search() { // Run asynchronous code const serp = require("serp");

var options = { host : "google.com", qs : { q: "seo", filter: 0, pws: 0 }, num : 100 };

const links = await serp.search(options); links.then((value) => { console.log(value); }) }

// Run the function search();`

I receive the following error

Screenshot_6

millette commented 2 years ago

@adnanhassan23, it's not a bug in the module.

Instead of:

links.then((value) => {
console.log(value);
})

Try:

console.log(links);

See https://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html to understand Promises better, and after that checkout https://www.geeksforgeeks.org/difference-between-promise-and-async-await-in-node-js/ to see how async/await work. Basically, those keywords are syntax sugar over Promises.