Back to Library
SubDomain
js • 1/27/2026
34
const axios = require("axios")
async function subdomain(domain) {
const url = `https://crt.sh/?q=${encodeURIComponent(domain)}&output=json`
try {
const res = await axios.get(url, {
timeout: 30000,
headers: {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120 Safari/537.36",
},
})
if (!Array.isArray(res.data)) return []
const subs = res.data
.map(v => v.name_value)
.flatMap(v => v.split("\n"))
.filter(v => v.endsWith(domain))
return [...new Set(subs)].sort()
} catch (e) {
throw new Error("Failed fetching subdomains")
}
}
module.exports = { subdomain }