Back to Library
Nhentai Downloader
js • 1/27/2026
12
const axios = require("axios")
const headers = {
"User-Agent": "Mozilla/5.0"
}
async function nhdl(id) {
try {
const api = `https://nhentai.net/api/gallery/${id}`
const { data } = await axios.get(api, { headers })
const mediaId = data.media_id
const pages = data.images.pages
const images = []
const extMap = {
j: "jpg",
p: "png",
g: "gif",
w: "webp"
}
pages.forEach((page, i) => {
const type = page.t
const ext = extMap[type] || "jpg"
const url = `https://i.nhentai.net/galleries/${mediaId}/${i + 1}.${ext}`
images.push(url)
})
if (images.length === 0) throw new Error("No images found")
return images
} catch (e) {
throw new Error(e.message)
}
}
module.exports = { nhdl }