【问题标题】:how to run serp node client如何运行serp节点客户端
【发布时间】:2022-01-30 19:31:17
【问题描述】:
我是 Node js 的新手。请让我知道如何使用此节点客户端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);
当我运行这个代码时,我收到以下错误
SyntaxError: await 仅在异步函数中有效
非常感谢所有帮助!
【问题讨论】:
标签:
node.js
express
puppeteer
mern
【解决方案1】:
在声明函数时,可以选择添加async 属性。这将使函数asynchronous。
这会启用函数内部的await 属性,并允许代码在继续之前等待任务完成。
声明一个异步函数的例子:
// 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();