Skip to content

🌍 World countries, states, regions, provinces, cities, and towns api. All Countries, States, Cities with ISO2, ISO3, Country Code, Phone Code, Capital, Native Language, Time zones, Latitude, Longitude, Region, Subregion, Flag Emoji, and Currency.

License

Notifications You must be signed in to change notification settings

montasim/countries-states-cities

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

COUNTRIES STATES CITIES

GitHub contributors badge GitHub language count badge GitHub top language badge GitHub code size badge GitHub repo size badge GitHub file count badge GitHub open issues badge GitHub closed issues badge GitHub open pull requests badge GitHub closed pull requests badge GitHub active milestones badge GitHub completed milestones badge GitHub license badge GitHub last commit badge GitHub Discussions badge

🌍 World countries, states, regions, provinces, cities, and towns api. All Countries, States, Cities with ISO2, ISO3, Country Code, Phone Code, Capital, Native Language, Time zones, Latitude, Longitude, Region, Subregion, Flag Emoji, and Currency.


CONTENTS:


FEATURES

  1. Get a list of Countries

    GET: https://countries-states-cities.vercel.app/api/v1/countries

    • Request Parameters

      No parameters

    • Example Success Response

      {
         "timeStamp": "2024-07-24T14:58:55.767Z",
         "success": true,
         "data": [
         {
            "_id": "66962e25e7dec94bff9a9ba9",
            "id": 19,
            "name": "Bangladesh",
            "iso3": "BGD",
            "iso2": "BD",
            "numeric_code": "050",
            "phone_code": "880",
            "capital": "Dhaka",
            "currency": "BDT",
            "currency_name": "Bangladeshi taka",
            "currency_symbol": "৳",
            "tld": ".bd",
            "native": "Bangladesh",
            "region": "Asia",
            "region_id": "3",
            "subregion": "Southern Asia",
            "subregion_id": "14",
            "nationality": "Bangladeshi",
            "timezones": [
               {
               "zoneName": "Asia/Dhaka",
               "gmtOffset": 21600,
               "gmtOffsetName": "UTC+06:00",
               "abbreviation": "BDT",
               "tzName": "Bangladesh Standard Time"
               }
            ],
            "translations": {
               "kr": "λ°©κΈ€λΌλ°μ‹œ",
               "pt-BR": "Bangladesh",
               "pt": "Bangladeche",
               "nl": "Bangladesh",
               "hr": "BangladeΕ‘",
               "fa": "Ψ¨Ω†Ϊ―Ω„Ψ§Ψ―Ψ΄",
               "de": "Bangladesch",
               "es": "Bangladesh",
               "fr": "Bangladesh",
               "ja": "バングラデシγƒ₯",
               "it": "Bangladesh",
               "cn": "ε­ŸεŠ ζ‹‰",
               "tr": "Bangladeş"
            },
            "latitude": "24.00000000",
            "longitude": "90.00000000",
            "emoji": "πŸ‡§πŸ‡©",
            "emojiU": "U+1F1E7 U+1F1E9"
            },
         ...
         ],
         "message": "Successfully retrieved countries matching criteria.",
         "status": 200,
         "route": "/api/v1/countries"
      }
  2. Get country details from ISO2 code

    GET: https://countries-states-cities.vercel.app/api/v1/countries/[ciso]

    • Request Parameters

      Name Located in Description Required Type
      [ciso] URL ISO2 Code of Country required string
      • Example Success Response

        {
           "timeStamp": "2024-07-24T14:58:55.767Z",
           "success": true,
           "data": {
              "_id": "66962e25e7dec94bff9a9ba9",
              "id": 19,
              "name": "Bangladesh",
              "iso3": "BGD",
              "iso2": "BD",
              "numeric_code": "050",
              "phone_code": "880",
              "capital": "Dhaka",
              "currency": "BDT",
              "currency_name": "Bangladeshi taka",
              "currency_symbol": "৳",
              "tld": ".bd",
              "native": "Bangladesh",
              "region": "Asia",
              "region_id": "3",
              "subregion": "Southern Asia",
              "subregion_id": "14",
              "nationality": "Bangladeshi",
              "timezones": [
                 {
                 "zoneName": "Asia/Dhaka",
                 "gmtOffset": 21600,
                 "gmtOffsetName": "UTC+06:00",
                 "abbreviation": "BDT",
                 "tzName": "Bangladesh Standard Time"
                 }
              ],
              "translations": {
                 "kr": "λ°©κΈ€λΌλ°μ‹œ",
                 "pt-BR": "Bangladesh",
                 "pt": "Bangladeche",
                 "nl": "Bangladesh",
                 "hr": "BangladeΕ‘",
                 "fa": "Ψ¨Ω†Ϊ―Ω„Ψ§Ψ―Ψ΄",
                 "de": "Bangladesch",
                 "es": "Bangladesh",
                 "fr": "Bangladesh",
                 "ja": "バングラデシγƒ₯",
                 "it": "Bangladesh",
                 "cn": "ε­ŸεŠ ζ‹‰",
                 "tr": "Bangladeş"
              },
              "latitude": "24.00000000",
              "longitude": "90.00000000",
              "emoji": "πŸ‡§πŸ‡©",
              "emojiU": "U+1F1E7 U+1F1E9"
           },
           "message": "Successfully retrieved the country.",
           "status": 200,
           "route": "/api/v1/countries/BD"
        }
    • Get a list of States

      GET: https://countries-states-cities.vercel.app/api/v1/states

      • Request Parameters

        No parameters

      • Example Success Response

        {
           "timeStamp": "2024-07-24T14:58:55.767Z",
           "success": true,
           "data": [
              {
                 "_id": "66962e1ae7dec94bff9a891d",
                 "id": 759,
                 "name": "Rangpur District",
                 "country_id": 19,
                 "country_code": "BD",
                 "country_name": "Bangladesh",
                 "state_code": "55",
                 "type": "district",
                 "latitude": "25.74679250",
                 "longitude": "89.25083350"
              },
              ...
           ],
           "message": "Successfully retrieved states matching criteria.",
           "status": 200,
           "route": "/api/v1/states"
        }
    • Get a list of States within country

      GET: https://countries-states-cities.vercel.app/api/v1/countries/[ciso]/states

      • Request Parameters

        Name Located in Description Required Type
        [ciso] URL ISO2 Code of Country required string
        • Example Success Response

          {
             "timeStamp": "2024-07-24T14:58:55.767Z",
             "success": true,
             "data": [
             {
             "_id": "66962e1ae7dec94bff9a891d",
             "id": 759,
             "name": "Rangpur District",
             "country_id": 19,
             "country_code": "BD",
             "country_name": "Bangladesh",
             "state_code": "55",
             "type": "district",
             "latitude": "25.74679250",
             "longitude": "89.25083350"
             },
             ...
             ],
             "message": "Successfully retrieved the state.",
             "status": 200,
             "route": "/api/v1/countries/BD/states"
          }
      • Get the state details from ISO2 Code

        GET: https://countries-states-cities.vercel.app/api/v1/countries/[ciso]/states/[siso]

        • Request Parameters

          Name Located in Description Required Type
          [ciso] URL ISO2 Code of Country required string
          [siso] URL ISO2 Code of State required string
          • Example Success Response

            {
               "timeStamp": "2024-07-24T14:58:55.767Z",
               "success": true,
               "data": {
                  "_id": "66962e1ae7dec94bff9a891d",
                  "id": 759,
                  "name": "Rangpur District",
                  "country_id": 19,
                  "country_code": "BD",
                  "country_name": "Bangladesh",
                  "state_code": "55",
                  "type": "district",
                  "latitude": "25.74679250",
                  "longitude": "89.25083350"
               },
               "message": "Successfully retrieved the state.",
               "status": 200,
               "route": "/api/v1/countries/BD/states/55"
            }
        • Get the list of cities in a state

          GET: https://countries-states-cities.vercel.app/api/v1/countries/[ciso]/states/[siso]/cities

          • Request Parameters

            Name Located in Description Required Type
            [ciso] URL ISO2 Code of Country required string
            [siso] URL ISO2 Code of State required string
            • Example Success Response

              {
                 "timeStamp": "2024-07-24T14:58:55.767Z",
                 "success": true,
                 "data": [
                    {
                       "_id": "66962e33e7dec94bff9abe90",
                       "id": 8577,
                       "name": "Rangpur",
                       "state_id": 759,
                       "state_code": "55",
                       "state_name": "Rangpur District",
                       "country_id": 19,
                       "country_code": "BD",
                       "country_name": "Bangladesh",
                       "latitude": "25.73333000",
                       "longitude": "89.25000000",
                       "wikiDataId": "Q2344570"
                    },
                    ...
                 ], 
                 "message": "Successfully retrieved the cities.",
                 "status": 200,
                 "route": "/api/v1/countries/BD/states/55/cities"
              }
          • Get a list of Cities within country

            GET: https://countries-states-cities.vercel.app/api/v1/countries/[ciso]/cities

            • Request Parameters

              Name Located in Description Required Type
              [ciso] URL ISO2 Code of Country required string
              • Example Success Response

                {
                   "timeStamp": "2024-07-24T14:58:55.767Z",
                   "success": true,
                   "data": [
                      {
                         "_id": "66962e33e7dec94bff9abe90",
                         "id": 8577,
                         "name": "Rangpur",
                         "state_id": 759,
                         "state_code": "55",
                         "state_name": "Rangpur District",
                         "country_id": 19,
                         "country_code": "BD",
                         "country_name": "Bangladesh",
                         "latitude": "25.73333000",
                         "longitude": "89.25000000",
                         "wikiDataId": "Q2344570"
                      },
                      ...
                   ], 
                   "message": "Successfully retrieved the cities.",
                   "status": 200,
                   "route": "/api/v1/countries/BD/cities"
                }

PREREQUISITES

  1. Node.js (v20.x or higher)
  2. Yarn (v1.22.x or higher)

Ensure you have Node.js and Yarn installed by running node -v and yarn -v in your terminal. These commands will display the current version of each installed on your system. If these are not installed, follow the installation instructions on the Node.js website and the Yarn website.


SETUP

  1. Clone the repository and navigate to the directory:

    git clone https://github.com/montasim/countries-states-cities.git
    cd countries-states-cities
  2. Install the dependencies:

    yarn install
  3. Configuring the Environment:

    Create a .env.development or .env.staging or .env.production file in the root directory of the project and populate it with the necessary environment variables. See the .env.example file for an example.


RUNNING THE SCRIPT

  1. Running the Application:

    To start the application in development mode, use:

    yarn dev

    This will run the server with nodemon, automatically restarting when any changes are made.

  2. To build and run the application in production mode, use:

    yarn start

    This will build the application and start the server using the built files.

    This script first builds the project by linting the code, fixing lint issues, running prettier, and then starts the application with pm2.

  3. Testing:

    To run the tests configured with Jest, use:

    yarn test

    This will build the project and then run all the Jest tests.

  4. Linting and Code Formatting:

    • To check for linting errors:

      yarn lint:check
    • To fix linting errors:

      yarn lint:fix
    • To check if files are formatted correctly:

      yarn prettier:check
    • To format files:

      yarn prettier:fix
  5. Generating Documentation:

    To generate code documentation with JSDoc, run:

    yarn generate-docs

    This will create documentation based on your JSDoc comments.

  6. Release Management:

    To create a new release, you can use:

    yarn release

    This will automatically bump the version, update the CHANGELOG, and create a commit and a tag.

    For minor or major releases:

    yarn release:minor
    yarn release:major
  7. Cleanup:

    To clean up dependencies and rebuild the project:

    yarn clean

    This command initializes the auto cleanup process and then forces a rebuild.

ERROR HANDLING


HOSTING

Deploy to Vercel

Step-by-step guide on setting up your own Vercel instance:

Vercel is the recommended option for hosting the files since it is free and easy to set up.

  1. Go to vercel.com.
  2. Click on Log in. Login page
  3. Sign in with GitHub by pressing Continue with GitHub. Sign in with GitHub
  4. Sign in to GitHub and allow access to all repositories if prompted.
  5. Fork this repo.
  6. Go back to your Vercel dashboard.
  7. To import a project, click the Add New... button and select the Project option. Add new project
  8. Click the Continue with GitHub button, search for the required Git Repository and import it by clicking the Import button. Alternatively, you can import a Third-Party Git Repository using the Import Third-Party Git Repository -> link at the bottom of the page. Select GitHub project
  9. Create a personal access token (PAT) here and enable the repo and user permissions (this allows access to see private repo and user stats).
  10. Copy all the .env.development file as environment variables in the Vercel dashboard.
  11. Click deploy, and you're good to go. See your domains to use the API!

TOOLS

  1. WebStorm
  2. Postman
  3. Swagify.io

ARTICLES


DO NOT FORGET TO DO


TUTORIALS


INSPIRATIONS

https://countrystatecity.in/


SPETIAL THANKS

github.com/dr5hn/countries-states-cities-database - For the countries, states, cities data.


CONTRIBUTE

Contributions are always welcome! Please read the contribution guidelines first.


CONTRIBUTORS

contributors


SPECIAL THANKS


LICENSE

Licence


CONTACT

linkedin icon github icon github icon web icon gmail icon facebook icon x icon



About

🌍 World countries, states, regions, provinces, cities, and towns api. All Countries, States, Cities with ISO2, ISO3, Country Code, Phone Code, Capital, Native Language, Time zones, Latitude, Longitude, Region, Subregion, Flag Emoji, and Currency.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published