List of world countries in JSON, CSV, XML and YAML with comprehensive metadata including names, codes, geography, currencies, and demographic information
npx @tessl/cli install tessl/npm-world-countries@5.1.0World Countries is a comprehensive dataset of world countries as defined by ISO Standard 3166-1, available in multiple data formats including JSON, CSV, XML, and YAML. The dataset contains detailed information for each country including names, ISO codes, geographic data, political information, currencies, languages, demographic data, and calling codes.
npm install world-countriesimport countries from "world-countries";For CommonJS:
const countries = require("world-countries");import countries from "world-countries";
// Access all countries data
console.log(`Total countries: ${countries.length}`);
// Find a specific country by ISO code
const usa = countries.find(country => country.cca2 === "US");
console.log(usa.name.common); // "United States"
// Filter by region
const europeanCountries = countries.filter(country => country.region === "Europe");
// Get all country names
const countryNames = countries.map(country => country.name.common);World Countries is organized around several key components:
dist/ directorydata/ directorytranslations and demonyms propertiesAccess to the complete array of country objects containing comprehensive metadata for all world countries and territories.
declare const countries: Countries;
export default countries;
type Countries = Country[];
interface Country {
name: CountryName;
tld: string[];
cca2: string;
ccn3: string;
cca3: string;
cioc?: string;
independent: boolean;
status: string;
unMember: boolean;
unRegionalGroup: "African Group" | "Asia and the Pacific Group" | "Eastern European Group" | "Latin American and Caribbean Group" | "Western European and Others Group" | "";
currencies: { [currencyCode: string]: Currency };
idd: IntlDirectDialingCode;
capital: string[];
altSpellings: string[];
region: string;
subregion: string;
languages: { [languageCode: string]: string };
translations: { [languageCode: string]: OfficialAndCommon };
latlng: [number, number];
demonyms: { [languageCode: string]: Demonyms };
landlocked: boolean;
borders: string[];
area: number;
flag: string;
}interface CountryName extends OfficialAndCommon {
native: {
[languageCode: string]: OfficialAndCommon;
};
}
interface OfficialAndCommon {
common: string;
official: string;
}
interface Currency {
name: string;
symbol: string;
}
interface IntlDirectDialingCode {
root: string;
suffixes: string[];
}
interface Demonyms {
f: string;
m: string;
}Each country object contains the following properties:
import countries from "world-countries";
// Find by ISO codes
const france = countries.find(c => c.cca3 === "FRA");
const usa = countries.find(c => c.cca2 === "US");
// Filter by independence status
const independentCountries = countries.filter(c => c.independent);
const territories = countries.filter(c => !c.independent);
// Filter by UN membership
const unMembers = countries.filter(c => c.unMember);
// Filter by region
const asianCountries = countries.filter(c => c.region === "Asia");
const europeanCountries = countries.filter(c => c.region === "Europe");import countries from "world-countries";
// Get all currencies used worldwide
const allCurrencies = countries.reduce((currencies, country) => {
Object.entries(country.currencies || {}).forEach(([code, currency]) => {
currencies[code] = currency;
});
return currencies;
}, {} as { [code: string]: Currency });
// Find landlocked countries
const landlockedCountries = countries.filter(c => c.landlocked);
// Get countries by language
const spanishSpeakingCountries = countries.filter(country =>
Object.values(country.languages || {}).includes("Spanish")
);
// Find countries in specific UN regional group
const africanGroupCountries = countries.filter(c =>
c.unRegionalGroup === "African Group"
);import countries from "world-countries";
// Calculate distances or find nearby countries using coordinates
const getDistance = (lat1: number, lng1: number, lat2: number, lng2: number) => {
// Haversine formula implementation
// ... distance calculation logic
};
// Find countries within a region by coordinates
const findNearbyCountries = (targetLat: number, targetLng: number, maxDistanceKm: number) => {
return countries.filter(country => {
const [lat, lng] = country.latlng;
const distance = getDistance(targetLat, targetLng, lat, lng);
return distance <= maxDistanceKm;
});
};
// Get countries by continent/region
const continentCountries = {
africa: countries.filter(c => c.region === "Africa"),
asia: countries.filter(c => c.region === "Asia"),
europe: countries.filter(c => c.region === "Europe"),
americas: countries.filter(c => c.region === "Americas"),
oceania: countries.filter(c => c.region === "Oceania"),
};The package also provides the same dataset in multiple formats located in the dist/ directory:
dist/countries.json - Standard JSON formatdist/countries-unescaped.json - JSON with unescaped Unicode charactersdist/countries.csv - Comma-separated values formatdist/countries.xml - XML formatdist/countries.yml - YAML formatThese files can be accessed directly if you need the data in a specific format outside of JavaScript/TypeScript.
Individual geographic data files are available in the data/ directory:
data/{cca3}.geo.json - GeoJSON geographic outlinesdata/{cca3}.topo.json - TopoJSON geographic datadata/{cca3}.svg - SVG flag filesWhere {cca3} is the three-letter ISO alpha-3 country code (e.g., usa.geo.json, fra.svg).