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

@babajidemm/african-countries-api

v2.0.2

Published

A Node.js library that provides APIs to get useful data about African countries including their cities (with more than 500 inhabitants).

Readme

African Countries API

A Node.js library for querying African country data (including cities with more than 500 inhabitants) from a local bundled dataset.

It is useful when you want country lookup features without managing your own country JSON files.

Who is this for?

  • Developers who need country metadata (name, region, languages, codes, borders, phone codes, etc.) in backend or tooling scripts.
  • Non-dev users who want quick copy-paste examples and simple command-line usage with Node.js.

Install

npm i @babajidemm/african-countries-api

Requires Node.js (LTS recommended).

Quick Start (Developer)

const api = require('@babajidemm/african-countries-api');

const result = api.byName('Algeria');

if (result.statusCode === 200) {
  const countries = JSON.parse(result.body.toString());
  console.log(countries[0].cca2); // DZ
}

Quick Start (Non-Developer / CLI)

After installing in a folder, run:

node -e "const api=require('@babajidemm/african-countries-api'); const r=api.byCapital('Accra'); console.log(r.statusCode); console.log(r.body.toString());"

This prints status code and the matching JSON array.

Response Format

Every method returns an http-response-object style response:

  • statusCode (number)
  • headers (object)
  • body (Buffer for success/not-found responses)
  • url (undefined)

Typical status codes:

  • 200 → found result(s)
  • 404 → no matches
  • 400 → invalid input shape for methods that require strict input (example: byCoordinates with non-array input)

API Methods

| Method | Description | Example Input | |---|---|---| | all() | Return all African countries | none | | byName(name) | Match common or official country name | 'Algeria' | | byCountryCode(code) | Match CCA2 code | 'DZ' | | byISOAlpha3CountryCode(code) | Match CCA3 code | 'DZA' | | byISONumericCountryCode(code) | Match numeric country code | '012' | | byOlympicCommiteeCode(cioc) | Match IOC code | 'ALG' | | byCurrency(currency) | Match currency symbol/code | 'DZD' | | byBorder(border) | Match neighboring country code | 'TUN' | | byLanguage(language) | Match language value (not key) | 'Arabic' | | byLatitude(lat) | Match latitude | 28 | | byLongitude(lng) | Match longitude | 3 | | byCoordinates([lat, lng]) | Match exact coordinate pair | [28, 3] | | byCapital(capital) | Match capital city | 'Algiers' | | byPhoneCode(phoneCode) | Match calling code | '213', '+213', 213 | | byRegion(region) | Match region | 'Africa' | | bySubregion(subregion) | Match subregion | 'Northern Africa' | | byDemonym(demonym) | Match demonym | 'Algerian' | | byAlternativeName(altName) | Match alternative spellings | 'Dzayer', 'Algérie' | | byTopLevelDomain(tld) | Match TLD | 'dz' or '.dz' |

Input Notes & Edge Cases

  • Most string lookups are case-sensitive.
  • byPhoneCode normalizes + signs and numeric-like values (for example '+213', '0213', and 213 resolve correctly).
  • byCoordinates requires an array; non-array input returns 400.
  • byTopLevelDomain accepts either 'dz' or '.dz' and normalizes to dot-prefixed format internally.

Local Development

npm install
npm test

Coverage report command:

npm run coverage

Data Source

Dataset note: the bundled data snapshot was last updated in July 2020.

Deno

Also available on Deno: https://deno.land/x/[email protected]

Contributing

  • Contributors: https://github.com/babajidemm/african-countries-api/graphs/contributors
  • Contribution guide: CONTRIBUTING

License

MIT. See LICENSE.