Registry / database / countries-list

countries-list

JSON →
library3.3.0jsnpmunverified

A comprehensive dataset of countries, languages, and continents with ISO 3166-1, ISO 639-1, and ISO 4217 codes. Includes names, native names, capitals, currencies, phone codes, and emoji flags. Version 3.3.0 ships TypeScript definitions, ESM and CJS builds. Updated regularly via community contributions. Differentiators: strong typing, multiple formats (JSON, CSV, SQL), minimal subset exports, and utility functions for lookups.

npm install countries-list
INSTALL
IMPORT
SIG · COUNTRIES-LIST
C
countries-list
databasejavascriptv3.3.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

countries
✓ import { countries } from 'countries-list'
✗ const countries = require('countries-list')
ESM module since v3. For CJS use require('countries-list/cjs/index.js').
getCountryData
✓ import { getCountryData } from 'countries-list'
✗ import getCountryData from 'countries-list'
Named export, not default.
ICountry
✓ import type { ICountry } from 'countries-list'
✗ import { ICountry } from 'countries-list'
Type import for TypeScript; not a runtime value.

Demonstrates importing countries and getEmojiFlag, iterating over the data, and writing a JSON file.

import { countries, getEmojiFlag } from 'countries-list'; import { writeFileSync } from 'fs'; // Generate a JSON file with country names and emoji flags const flagData: Record<string, { name: string; flag: string }> = {}; for (const [code, country] of Object.entries(countries)) { flagData[code] = { name: country.name, flag: getEmojiFlag(code), }; } writeFileSync('flags.json', JSON.stringify(flagData, null, 2)); console.log('Generated flags.json with', Object.keys(flagData).length, 'countries.');
Debug
Known issues
breakingVersion 3 changed data structure: country.phone is now an array (previously a number or string).
fix
Update code to handle phone as array, e.g., country.phone[0] for primary code.
affects: >=3.0.0
deprecatedThe old 'minimal' exports path changed in v3. Previously accessible via separate files, now under 'countries-list/minimal/'.
fix
Use import from 'countries-list/minimal/countries.2to3.min.json' etc.
affects: >=3.0.0
gotchagetEmojiFlag accepts ISO 3166-1 alpha-2 code as string, but does not validate; returns empty string for invalid codes.
fix
Always validate country code before calling getEmojiFlag.
affects: *
Errors
Common errors & fixes
Cannot find module 'countries-list'
Missing package installation or incorrect import path.
fix
Run 'npm install countries-list' and use correct import: 'import { countries } from 'countries-list''
TypeError: country.phone.map is not a function
In v2, country.phone was a number/string; in v3 it's an array. Code expects array but data is old or vice versa.
fix
Ensure you use v3 data and access phone as array: country.phone[0] or country.phone.join(', ').
Module not found: Can't resolve 'countries-list' in '/path/to/file'
Webpack or bundler not resolving the package correctly due to missing main field or incorrect export.
fix
Ensure package.json 'main' points to cjs/index.js and 'module' to mjs/index.js. For webpack, add resolve.alias or use explicit path.
Upgrade
Version history
3.3.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
6
OpenAI (training)
1
Resources
countries-list — npm install countries-list · libregistry