Skip to content

Instantly share code, notes, and snippets.

@xaliphostes
Last active October 11, 2023 05:47
Show Gist options
  • Save xaliphostes/e22638dc169c0cff7f238a36fef5c65b to your computer and use it in GitHub Desktop.
Save xaliphostes/e22638dc169c0cff7f238a36fef5c65b to your computer and use it in GitHub Desktop.
async/await for npm
// Example function
export const fetchPackageInfo = async (pkgName: string, signal: AbortSignal): Promise<NpmPackage> => {
const response = await fetch(`https://registry.npmjs.org/${pkgName}`, { signal })
if (response.status === 200) {
return response.json();
} else {
throw response.text();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment