Get Country Information

You can use the getCountryInfo function to retrieve information about a specific country. This function takes the country name as input and optionally an array of specific fields to retrieve. If no specific fields are provided, all available data for the country will be returned.

const { getCountryInfo } = require('countrys-info');

// Get information about a specific country
const countryData = getCountryInfo('Afghanistan');
console.log(countryData);

// Get a specific field of a country
const capitalEn = getCountryInfo('China', 'capital_en');
console.log(capitalEn);

// Get multiple fields of a country
const countryFields = getCountryInfo('China', ['capital_en', 'code_2', 'tld']);
console.log(countryFields);

Last updated

Was this helpful?