npm i xcountry-state-city
let {getAllCountries} = require('xcountry-state-city');
getAllCountries();
getAllCountries();
// it will return array of countries object
[
{
"id":101,
"name":"India",
"iso2":"IN",
"iso3":"IND",
"phone_code":"91",
"capital":"New Delhi",
"region":"Asia"
},
...many more
]
getCountryDetailByCountryCode(CountryCode:String);
// it will return details of the country
{
"id":101,
"name":"India",
"iso2":"IN",
"iso3":"IND",
"phone_code":"91",
"capital":"New Delhi",
"region":"Asia"
}
getStatesByCountry( countryCode:string );
// it will return array of states
[
{
"id": 4023,
"name": "Andaman and Nicobar Islands",
"state_code": "AN"
},
...many more
]
getStateDetailByStateAndCountry(countryCode:string , stateCode:string)
// it will return details of state
[
{
"id":4039,
"name":"Madhya Pradesh",
"country_id":101,
"country_code":"IN",
"country_name":"India",
"state_code":"MP"
}
]
getCitiesByStateAndCountry( countryCode:string , stateCode:string );
// it will return array of cities
[
{
"id":132166,
"name":"Indore",
"state_code":"MP",
"country_code":"IN"
},
...many more
]