Skip to content

Instantly share code, notes, and snippets.

@gauravmuk
Created July 7, 2019 18:29
Show Gist options
  • Save gauravmuk/0427988c04deb7c5136c60a2e732c543 to your computer and use it in GitHub Desktop.
Save gauravmuk/0427988c04deb7c5136c60a2e732c543 to your computer and use it in GitHub Desktop.
Question Fun Level - 10
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