Geographic data, straight from npm.
Nine packages under the @countrystatecity scope, published from the same dataset the API serves. Install the slice you need, ship it with your bundle, and make no network call at runtime.
npm install @countrystatecity/countries
The packages.
Each one stands alone, so a phone input does not have to ship 153,765 cities.
npm i @countrystatecity/countries
npm i @countrystatecity/countries-browser
npm i @countrystatecity/timezones
npm i @countrystatecity/currencies
npm i @countrystatecity/phonecodes
npm i @countrystatecity/postalcodes
npm i @countrystatecity/geojson
npm i @countrystatecity/translations
npm i @countrystatecity/cli
Package or API?
- the data ships with your build and has to work offline
- a dropdown should open with no round trip
- you can redeploy to pick up a data correction
- corrections should reach users the day they land
- you want fuzzy search, autocomplete or nearby lookups
- bundle size matters more than one request
Questions.
Which package should I install first?
@countrystatecity/countries. It carries countries, states and cities together, which is what an address form needs. Add the smaller packages only when you want dial codes, currencies, timezones or postcodes.
Do the packages need an API key?
No. The data ships inside the package and resolves locally, so there is no network call and nothing to authenticate. A key is only needed for the hosted API.
How do the packages relate to the API?
They are built from the same dataset. The packages give you a snapshot that updates when you upgrade; the API gives you the current data on every request, plus search, autocomplete and nearby lookups.
Is the data open source?
Yes. The underlying dataset is the countries-states-cities-database project on GitHub, and the packages are published from it.
What about bundle size?
Install only the slice you use. A phone input needs @countrystatecity/phonecodes, not the full city list, and @countrystatecity/countries-browser keeps the data out of your bundle entirely by loading it from a CDN.
Need live data instead of a snapshot?
The API serves the same dataset over REST and GraphQL, with fuzzy search, autocomplete and a change feed.