npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

country-codes-flags

v1.26.4

Published

**country-codes-flags** is a backend utility package that provides a **complete dataset of over 200 countries** with accurate details — including:

Readme

🌍 country-codes-flags

country-codes-flags is a backend utility package that provides a complete dataset of over 200 countries with accurate hierarchical details — including:

  • 🏳️ Country Name
  • 🔤 ISO Short Code (Alpha-2 / Alpha-3)
  • ☎️ Dial Code
  • 🏁 Flag Image (Local SVG File)
  • 🗺️ States / Provinces
  • 🏙️ Districts / Cities

This package is built for Node.js backends, offering an easy way to access standardized country, state, and city data — without maintaining them manually.


🚀 Powered By

This package is proudly powered by Petabyte Innovations 💡


📦 Installation

Install using npm:

npm install country-codes-flags

📊 Data Structure

The package follows a nested hierarchical structure:

Country → State → District (City)

Example Structure:

{
  "id": 1,
  "name": "Afghanistan",
  "short_name": "AFG",
  "status": "Country",
  "dial_code": "+93",
  "max_nsn_length": 9,
  "flags_icon": "flags/af.svg",
  "national_language": "Dari",
  "states": [
    {
      "name": "Badakhshan",
      "districts": ["Argo", "Baharak", "Darayim"]
    }
  ]
}

⚙️ Setup in Express

Step-1 :- Making Flags Image Files Accessible

import express from "express";
const app = express();

app.use("/flags", express.static("node_modules/country-codes-flags/flags"));

app.listen(5000, () => {
  console.log("Server running on port 5000");
});

Step-2 :- 🌐 Access the Flags

http://localhost:5000/flags/in.svg

🧩 Step 3:- Create an API and Use Package Functions

import express from "express";
import country from "country-codes-flags";

const app = express();

app.use("/flags", express.static("node_modules/country-codes-flags/flags"));

app.get("/getAllCountries", (req, res) => {
  let allcountries = country.getAllCountriesInfo();

  res.send({
    allcountries,
    apiurl: "http://localhost:8000/",
  });
});

app.listen(8000, () => {
  console.log("✅ Server running on http://localhost:8000");
});

📦 API Response Example

{
  "name": "India",
  "short_name": "IND",
  "dial_code": "+91",
  "states": [
    {
      "name": "Rajasthan",
      "districts": ["Jaipur", "Jodhpur", "Udaipur"]
    }
  ]
}

🖼️ Step 4: Display Flags in Your Frontend

HTML

<img src="http://localhost:8000/flags/in.svg" alt="India Flag" width="40" />

JSX

<img src={`${apiurl}flags/${country.flags_icon}`} alt={country.name} width={40} />

Vue

<img :src="`${apiurl}flags/${country.flags_icon}`" :alt="country.name" width="40" />

⚡ Methods & Example


1. Get All Countries Info

const country = require("country-codes-flags");

const allCountries = country.getAllCountriesInfo();
console.log(allCountries);

2. Get Country Info

country.getCountryInfo("India");
country.getCountryInfo("IND");
country.getCountryInfo("+91");
country.getCountryInfo(100);

3. Get All Country Names

country.getCountryNames();

4. Get Single Country Name

country.getCountryName("India");

5. Get All Country Short Names

country.getCountryShortNames();

6. Get Single Country Short Name

country.getCountryShortName("India");

7. Get All Country Dial Codes

country.getCountryDialCodes();

8. Get Single Country Dial Code

country.getCountryDialCode("India");

9. Get States of a Country 🗺️

const states = country.getStates("India");
console.log(states);

10. Get Districts / Cities 🏙️

const districts = country.getDistricts("India", "Rajasthan");
console.log(districts);

🚀 Features

  • ✅ Country + State + City hierarchy
  • ✅ No external APIs required
  • ✅ Fast and lightweight
  • ✅ Easy to integrate
  • ✅ Backend optimized

📌 Use Cases

  • 🌐 Country → State → City dropdowns
  • 📱 User registration forms
  • 🛒 E-commerce shipping systems
  • 📊 Geo-based analytics

📁 Package Structure

country-codes-flags/
│
├── data/
│   └── countries.json
│
├── flags/
│   └── *.svg
│
├── index.js
└── package.json

👨‍💻 Author

Made with ❤️ by Petabyte Innovations


📄 License

MIT License