A Node.js library that provides APIs to get useful data about African countries including their cities (with more than 500 inhabitants).
# 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
```sh
npm i @babajidemm/african-countries-api
```
Requires Node.js (LTS recommended).
## Quick Start (Developer)
```js
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:
```sh
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 …