I'm extremely newbie at Node js. Please let me know how can i work with this node client https://www.npmjs.com/package/serp
const serp = require("serp");
var options = {
host : "google.fr",
qs : {
q : "test",
filter : 0,
pws : 0
},
num : 100
};
const links = await serp.search(options);
When I run this the code, I receive the following error
SyntaxError: await is only valid in async function
VERY grateful for all help!
When declaring functions there is an option to add an async property. This will make the function asynchronous.
This enables the await
property inside the function and allows the code to wait for a task to be completed before moving forward.
Example of declaring an asynchronous function:
// Declare the function
async function search() {
// Run asynchronous code
const serp = require("serp");
var options = {
host : "google.fr",
qs : {
q: "test",
filter: 0,
pws: 0
},
num : 100
};
const links = await serp.search(options);
}
// Run the function
search();