Skip to content

nicholidev/country-cities

Repository files navigation

Countries, States, Cities

country-cities

NPM downloads NPM version License Maintained with Nicholi

Install

npm i country-cities


How to use

  • Get Countries

import { countries } from "country-cities"


All of Countries

countries.all()
[
  {
    "isoCode": "US",
    "name": "United State",
    "phonecode": "1",
    "flag": "🇺🇸",
    "currency": "USD",
    "latitude": "38.00000000",
    "longitude": "-97.00000000",
    "timezones": [
      {
        "zoneName": "America/Adak",
        "gmtOffset": -36000,
        "gmtOffsetName": "UTC-10:00",
        "abbreviation": "HST",
        "tzName": "Hawaii–Aleutian Standard Time"
      },
	  {
        "zoneName": "America/Kentucky/Louisville",
        "gmtOffset": -18000,
        "gmtOffsetName": "UTC-05:00",
        "abbreviation": "EST",
        "tzName": "Eastern Standard Time (North America)"
      },
	  ...
    ]
  },
  {
    "isoCode": "FR",
    "name": "France",
    "phonecode": "33",
    "flag": "🇫🇷",
    "currency": "EUR",
    "latitude": "46.00000000",
    "longitude": "2.00000000",
    "timezones": [
      {
        "zoneName": "Europe/Paris",
        "gmtOffset": 3600,
        "gmtOffsetName": "UTC+01:00",
        "abbreviation": "CET",
        "tzName": "Central European Time"
      }
    ]
  }
]

Get country by its code

countries.getByCode("US")
{
  "isoCode": "US",
  "name": "United State",
  "phonecode": "1",
  "flag": "🇺🇸",
  "currency": "USD",
  "latitude": "38.00000000",
  "longitude": "-97.00000000",
  "timezones": [
    {
      "zoneName": "America/Adak",
      "gmtOffset": -36000,
      "gmtOffsetName": "UTC-10:00",
      "abbreviation": "HST",
      "tzName": "Hawaii–Aleutian Standard Time"
    },	  
    {
      "zoneName": "America/Kentucky/Louisville",
      "gmtOffset": -18000,
      "gmtOffsetName": "UTC-05:00",
      "abbreviation": "EST",
      "tzName": "Eastern Standard Time (North America)"
    },	  	 ...
  ]
}



  • Get States

import { states } from "country-cities"


All of States in the world

states.all()
[
  {
    countryCode: "US",
    isoCode: "VA",
    latitude: "37.43157340",
    longitude: "-78.65689420",
    name: "Virginia"
  },
  {
    countryCode: "US",
    isoCode: "IL",
    latitude: "40.63312490",
    longitude: "-89.39852830",
    name: "Illinois"
  },
  ...
]

Get States by Country

states.getByCountry("US")
[
  {
    countryCode: "US",
    isoCode: "VA",
    latitude: "37.43157340",
    longitude: "-78.65689420",
    name: "Virginia"
  },
  {
    countryCode: "US",
    isoCode: "IL",
    latitude: "40.63312490",
    longitude: "-89.39852830",
    name: "Illinois"
  },
  ...
]

Get State by Code

states.getByCode("VA", "US")

Important: The country code should be entered second parameter

{
  countryCode: "US",
  isoCode: "VA",
  latitude: "37.43157340",
  longitude: "-78.65689420",
  name: "Virginia"
},



  • Get Cities

import { cities } from "country-cities"


All of Cities

cities.all()

[
  {
    countryCode: "AU",
    latitude: "-31.12756000",
    longitude: "150.90711000",
    name: "Hillvue",
    stateCode: "NSW",
  },
  {
    countryCode: "AU",
    latitude: "-33.91878000",
    longitude: "150.86314000",
    name: "Hinchinbrook",
    stateCode: "NSW",
  },
  ...
]

Get Cities by Country

cities.getByCountry("AU")
[
  {
    countryCode: "AU",
    latitude: "-31.12756000",
    longitude: "150.90711000",
    name: "Hillvue",
    stateCode: "NSW",
  },
  {
    countryCode: "AU",
    latitude: "-33.91878000",
    longitude: "150.86314000",
    name: "Hinchinbrook",
    stateCode: "NSW",
  },
  ...
]

Get Cities by State and Country

cities.getByState("NSW", "AU")

Important: The country code should be entered second parameter

[
  {
    countryCode: "AU",
    latitude: "-31.12756000",
    longitude: "150.90711000",
    name: "Hillvue",
    stateCode: "NSW",
  },
  {
    countryCode: "AU",
    latitude: "-33.91878000",
    longitude: "150.86314000",
    name: "Hinchinbrook",
    stateCode: "NSW",
  },
  ...
]