Skip to content

Instantly share code, notes, and snippets.

@ergomancer
Last active January 3, 2026 16:03
Show Gist options
  • Select an option

  • Save ergomancer/61c721e41b9a9d81306ad2224dee3c0e to your computer and use it in GitHub Desktop.

Select an option

Save ergomancer/61c721e41b9a9d81306ad2224dee3c0e to your computer and use it in GitHub Desktop.
A script to fetch Purchasing Power Parity (PPP) data from the World Bank API.
/*
v1.0.x
NPM Package: npm install countrypppdata
*/
const axios = require("axios");
const { getCodes, getCodeList } = require("country-list");
async function fetchCountryData() {
let countries = getCodes();
const countriesList = getCodeList();
let countryName, pf;
const result = [];
const miss = [];
for (country of countries) {
try {
let pfRes = await axios.get(
"https://api.worldbank.org/v2/country/" +
country +
"/indicator/pa.nus.pppc.rf?format=json"
);
let pfDataset = pfRes.data[1];
for (pfData of pfDataset) {
countryName = pfData["country"]["value"];
pf = pfData["value"];
if (pf != null) {
break;
}
}
pf = pf || 0.7;
result.push({ country, countryName, pf });
} catch (err) {
miss.push(country);
}
}
for (code of miss) {
countryName = countriesList[code.toLowerCase()];
pf = 0.7;
result.push({ country, countryName, pf });
}
return result;
}
module.exports = fetchCountryData;
@MuhammadQuran17
Copy link

Thanks a lot for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment