Get Data From Async Function
i'm trying to do a little website like sickgearr for my seedbox : i want a search form which will send a search query to my torrent providers using this api : https://github.com/J
Solution 1:
Your search function is using async
/await
.
It means the search function is asynchrone and returns a Promise
.
You should await its result (line 23).
https://javascript.info/async-await
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function
const express = require('express')
const bodyParser = require('body-parser')
const app = express()
constTorrentSearchApi = require('torrent-search-api')
const tableify = require('tableify')
TorrentSearchApi.enableProvider('Yggtorrent','Login', 'Password')
app.use(express.static('public'))
app.use(bodyParser.urlencoded({ extended: true }))
app.set('view engine', 'ejs')
const search = async query => {
const loweredQuery = query.toLowerCase()
const torrents = awaitTorrentSearchApi.search(loweredQuery, 'All', 20)
returnJSON.stringify(torrents)
}
app.get('/', (_, res) => res.render('index'))
app.post('/', async (req, res) => {
const torrents = awaitsearch(req.body.torrent) // Right hereconst htmlTable = tableify(torrents)
res.render('results', htmlTable)
})
app.listen(3000, function () {
console.log('Example app listening on port 3000!')
})
Post a Comment for "Get Data From Async Function"