{"id":42547,"library":"countries-list","title":"countries-list","description":"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.","status":"active","version":"3.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/annexare/Countries","tags":["javascript","country","countries","continent","emoji","languages","capital","currency","data","typescript"],"install":[{"cmd":"npm install countries-list","lang":"bash","label":"npm"},{"cmd":"yarn add countries-list","lang":"bash","label":"yarn"},{"cmd":"pnpm add countries-list","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM module since v3. For CJS use require('countries-list/cjs/index.js').","wrong":"const countries = require('countries-list')","symbol":"countries","correct":"import { countries } from 'countries-list'"},{"note":"Named export, not default.","wrong":"import getCountryData from 'countries-list'","symbol":"getCountryData","correct":"import { getCountryData } from 'countries-list'"},{"note":"Type import for TypeScript; not a runtime value.","wrong":"import { ICountry } from 'countries-list'","symbol":"ICountry","correct":"import type { ICountry } from 'countries-list'"}],"quickstart":{"code":"import { countries, getEmojiFlag } from 'countries-list';\nimport { writeFileSync } from 'fs';\n\n// Generate a JSON file with country names and emoji flags\nconst flagData: Record<string, { name: string; flag: string }> = {};\nfor (const [code, country] of Object.entries(countries)) {\n  flagData[code] = {\n    name: country.name,\n    flag: getEmojiFlag(code),\n  };\n}\nwriteFileSync('flags.json', JSON.stringify(flagData, null, 2));\nconsole.log('Generated flags.json with', Object.keys(flagData).length, 'countries.');","lang":"typescript","description":"Demonstrates importing countries and getEmojiFlag, iterating over the data, and writing a JSON file."},"warnings":[{"fix":"Update code to handle phone as array, e.g., country.phone[0] for primary code.","message":"Version 3 changed data structure: country.phone is now an array (previously a number or string).","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Use import from 'countries-list/minimal/countries.2to3.min.json' etc.","message":"The old 'minimal' exports path changed in v3. Previously accessible via separate files, now under 'countries-list/minimal/'.","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Always validate country code before calling getEmojiFlag.","message":"getEmojiFlag accepts ISO 3166-1 alpha-2 code as string, but does not validate; returns empty string for invalid codes.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"search_vec":"'-1':15,18 '3.3.0':35 '3166':14 '4217':21 '639':17 'build':42 'capit':27,70 'cjs':41 'code':22,30 'communiti':46 'comprehens':5 'contin':11,67 'contribut':47 'countri':2,8,65,66 'countries-list':1 'csv':54 'currenc':28,71 'data':72 'dataset':6 'definit':38 'differenti':48 'emoji':32,68 'esm':39 'export':58 'flag':33 'format':52 'function':61 'includ':23 'iso':13,16,20 'javascript':64 'json':53 'languag':9,69 'list':3 'lookup':63 'minim':56 'multipl':51 'name':24,26 'nativ':25 'phone':29 'regular':44 'ship':36 'sql':55 'strong':49 'subset':57 'type':50 'typescript':37,73 'updat':43 'util':60 'version':34 'via':45","created_at":"2026-06-05T16:55:30.682899+00:00","updated_at":"2026-06-05T16:55:30.682899+00:00","problems":[{"fix":"Run 'npm install countries-list' and use correct import: 'import { countries } from 'countries-list''","cause":"Missing package installation or incorrect import path.","error":"Cannot find module 'countries-list'"},{"fix":"Ensure you use v3 data and access phone as array: country.phone[0] or country.phone.join(', ').","cause":"In v2, country.phone was a number/string; in v3 it's an array. Code expects array but data is old or vice versa.","error":"TypeError: country.phone.map is not a function"},{"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.","cause":"Webpack or bundler not resolving the package correctly due to missing main field or incorrect export.","error":"Module not found: Can't resolve 'countries-list' in '/path/to/file'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"http://annexare.github.io/Countries/","github":"https://github.com/annexare/Countries","docs":null,"changelog":null,"pypi":null,"npm":"countries-list","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}