Created
July 7, 2019 18:29
-
-
Save gauravmuk/0427988c04deb7c5136c60a2e732c543 to your computer and use it in GitHub Desktop.
Question Fun Level - 10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fetch = require('node-fetch'); | |
async function getDependencies(packageName) { | |
const url = `https://registry.npmjs.org/${packageName}/latest`; | |
try { | |
const response = await fetch(url); | |
const body = await response.json(); | |
return Object.keys(body.dependencies); | |
} catch (err) { | |
return []; | |
} | |
} | |
async function getAllDependencies(packageName) { | |
const deps = await getDependencies(packageName); | |
const allDeps = await Promise.all(deps.map(async dep => { | |
return await getAllDependencies(dep); | |
})); | |
return [...new Set(deps.concat(...allDeps))]; | |
} | |
getAllDependencies('forever').then(values => { | |
console.log(values.length); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment