![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
country-city-search
Advanced tools
The process of accessing and utilizing country and city information programmatically, making it a valuable tool for developers working with geographic data in their projects.
A Project to get Data about the country cities and states according the request.
Install country city search with npm
npm i country-city-search
import { getAllCountries, getCitiesByStateAndCountry, getCityByNameAndCountryData, searchCityByName } from "country-city-search";
const Home = () => {
const fetchData = async () => {
//Get All Countries Name with country code in single array
const allCountries = await getAllCountries();
// Output : ['Afghanistan (AF)', 'Albania (AL)',....]
//------------------------------------------------------
//Get City object using city name, state name and country name
const cityObject = await getCityByNameAndCountryData({
cityName: "rajkot",
state_name: "gujarat",
country_name: "India",
});
/*Output :
{
country_code: "IN";
country_id: "101";
country_name: "India";
id: "133679";
latitude: "22.33333000";
longitude: "70.83333000";
name: "Rajkot";
state_code: "GJ";
state_id: "4030";
state_name: "Gujarat";
time_zone_name: "Asia/Kolkata";
wikiDataId: "Q11854";
}
*/
//------------------------------------------------------------
//Get List array of cities object using state and country name
const allCitiesFromState = await getCitiesByStateAndCountry("gujarat", "India");
/*
Output :
[{
"id": "57588",
"name": "Abrama",
"state_id": "4030",
"state_code": "GJ",
"state_name": "Gujarat",
"country_id": "101",
"country_code": "IN",
"country_name": "India",
"latitude": "20.85865000",
"longitude": "72.90648000",
"wikiDataId": "Q490916",
"time_zone_name": "Asia/Kolkata"
}....]
*/
//------------------------------------------------------------
//Search City by it's Name
const city = await searchCityByName("ahmedabad");
/*
Output :
[
{
"id": "57606",
"name": "Ahmedabad",
"state_id": "4030",
"state_code": "GJ",
"state_name": "Gujarat",
"country_id": "101",
"country_code": "IN",
"country_name": "India",
"latitude": "23.02579000",
"longitude": "72.58727000",
"wikiDataId": "Q1070",
"time_zone_name": "Asia/Kolkata"
}, ...
]
*/
//------------------------------------------------------------
};
useEffect(() => {
fetchData();
});
return (
<>
<div> Simple Examples for country-city-search package</div>
</>
);
};
For support, email dharmeshpal42@gmail.com
FAQs
The process of accessing and utilizing country and city information programmatically, making it a valuable tool for developers working with geographic data in their projects.
We found that country-city-search demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.