Search code examples
node.jsmongodbapidictionaryiso-3166

nodejs - iso 3166 - Alternative countries names


I'm writing a program that extracts countries from https://restcountries.eu/ I'm using the data to save in my mongo DB and update it. ofc, the data doesn't change too often, but this is for a decade forward.

const COUNTRIES_URL = 'https://restcountries.eu/rest/v2/all';
const axios = require('axios');

exports.httpCrawl = () => (
  axios.get(COUNTRIES_URL).then(response => (
    response.data.map(country => ({
      name: country.name,
      digits2: country.alpha2Code,
      digits3: country.alpha3Code,
      countryId: country.numericCode,
      flag: country.flag
    })))));

now when the data is in the DB, I want to use it to map other entities I'm getting from other APIs, for example, sports games. but the games come with the country's alternative name (for example England instead of Great Britain).

Is there a way to map the country's alternative names to the iso 3166 name/id?


Solution

  • You could leverage a service like Google Places API, this would allow you to pull associated country information based on alternative name or partial information.