私は、ポストリクエストを持つExpressセットアップを持っています。私は(async (req, res)
へreq
を追加しようとしました:self-called async関数の中に引数を挿入するには?
router.post('/search', (req, res) => {
;(async (req, res) => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto(`https://www.google.com/search?tbm=bks&q=%22this+is%22`)
const result = await page.evaluate(() => {
console.log('CLAUSESS:', req.body.clauses)
const clauses = req.body.clauses
return clauses.map(clause => clause.textContent)
})
result.join('\n')
await browser.close()
res.send(result)
})()
})
はしかし、私はまだ、このエラーを取得しています:
(node:5757) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Evaluation failed: ReferenceError: req is not defined at :2:32
これを行うための適切な方法は何ですか?