在异步函数中使用查询

Using query in async function

我想添加一个选项以使用查询在推文流中搜索特定字符串。 我想在代码中切换 'coding' 字符串以获取从 URL 获得的查询。 我该怎么做?

let nowTweets = (cb) => {
T.get('search/tweets', { q: 'coding', count: 10 }, function (err, data,response) {
    const tweets = data.statuses
    .map(tweet => tweet.text)
    console.log(tweets);
    cb(tweets)
})

}

app.get('/tweets', (req, res) => {
nowTweets(tweets => {
    res.send('Tweets: ' + '\n' + tweets)
})

})

谢谢!

使用 req.paramsreq.query 之类的东西从路线的 url 中获取搜索字符串,并将其作为参数传递给 nowTweets()

对于快递: https://expressjs.com/en/api.html#req.params https://expressjs.com/en/api.html#req.query