Last active
October 11, 2023 05:47
-
-
Save xaliphostes/e22638dc169c0cff7f238a36fef5c65b to your computer and use it in GitHub Desktop.
async/await for npm
This file contains hidden or 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
// 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