I'm using NodeJS to fetch the NPM registry with the code below.
import fetch from "node-fetch";
let url = "https://registry.npmjs.com/[package-name]";
let settings = { method: "Get" };
fetch(url, settings)
.then(res => res.json())
.then((json) => {
console.log(json.versions)
});
So, the response that I get in my result is:
{
_id: '123456789',
name: 'package-name',
'dist-tags': { latest: '2.0.0' },
versions: {
'2.0.0': '...'
}
...
}
I am trying to read the 'versions' section, but the issue I have is that the version number 2.0.0 is encased in quotes and it might change but I want to find that value. How can I read it?
Thanks in advance, and let me know any other info I missed.
You'll have to check if the versions has the key you want.
Or you could iterate through
Object.keys(response.versions)
and handle each version entry as you wish.