xkcd/lib/xkcd.js
Henrique Dias 89b2517ffc feat: xkcd cloner
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
2019-04-27 09:56:53 +01:00

21 lines
417 B
JavaScript

const fetch = require('node-fetch')
async function getLatestId () {
const raw = await fetch(`https://xkcd.com/info.0.json`)
const data = await raw.json()
return data.num
}
async function getComic (id) {
const raw = await fetch(`https://xkcd.com/${id}/info.0.json`)
const data = await raw.json()
const img = await fetch(data.img)
return { data, img }
}
module.exports = {
getLatestId,
getComic
}