countries-api
v2.0.2
Published
module to get world countries with ease
Downloads
1,204
Readme
Countries-Api
Module which expose some usefull Api's that can be very handy when dealing with countries
Country JSON object will be like
{
"name": {
"common": "Aruba",
"official": "Aruba",
"native": {
"nld": {
"official": "Aruba",
"common": "Aruba"
},
"pap": {
"official": "Aruba",
"common": "Aruba"
}
}
},
"tld": [".aw"],
"cca2": "AW",
"ccn3": "533",
"cca3": "ABW",
"cioc": "ARU",
"currency": ["AWG"],
"callingCode": ["297"],
"capital": "Oranjestad",
"altSpellings": ["AW"],
"region": "Americas",
"subregion": "Caribbean",
"languages": {
"nld": "Dutch",
"pap": "Papiamento"
},
"translations": {
"deu": {"official": "Aruba", "common": "Aruba"},
"fra": {"official": "Aruba", "common": "Aruba"},
"hrv": {"official": "Aruba", "common": "Aruba"},
"ita": {"official": "Aruba", "common": "Aruba"},
"jpn": {"official": "\u30a2\u30eb\u30d0", "common": "\u30a2\u30eb\u30d0"},
"nld": {"official": "Aruba", "common": "Aruba"},
"por": {"official": "Aruba", "common": "Aruba"},
"rus": {"official": "\u0410\u0440\u0443\u0431\u0430", "common": "\u0410\u0440\u0443\u0431\u0430"},
"spa": {"official": "Aruba", "common": "Aruba"},
"fin": {"official": "Aruba", "common": "Aruba"},
"zho": {"official": "\u963F\u9C81\u5DF4", "common": "\u963F\u9C81\u5DF4"}
},
"latlng": [12.5, -69.96666666],
"demonym": "Aruban",
"landlocked": false,
"borders": [],
"area": 180
}
Author: Gaurav Joshi
- Countries-Api
- Methods
findByCountryCode(countryCode)
findByCCN3(ccn3)
findByCCA3(cca3)
findByCIOC(cioc)
findByCapital(capital)
findBySubRegion(subRegion)
findByRegion(region)
findByResidentName(name)
findByLandLock(boolean)
findByArea(area)
findByCurrency(currency)
findByCallingCode(code)
findBySpellings(spells)
findByBorders(borders)
findByLat(latitude)
findByLong(longitude)
findByLatLong(array of lat and long)
findByName(name)
findByOfficialName(officialName)
findByLanguage(name)
findAll()
findById()
- Methods
Start
const Countries = require('Countries-Api');
Uses https://github.com/GJ2511/response-format module for formating results
Methods
findByCountryCode(countryCode)
Returns a 200 Success where:
statusCode
- 200error
- falsemessage
- optional message.data
- optional payload.
Countries.findByCountryCode('AW');
Generates the following response payload:
{"statusCode":200,"error":false,"data":[{"name":{"common":"Aruba","official":"Aruba","native":{"nld":{"official":"Aruba","common":"Aruba"},"pap":{"official":"Aruba","common":"Aruba"}}},"tld":[".aw"],"cca2":"AW","ccn3":"533","cca3":"ABW","cioc":"ARU","currency":["AWG"],"callingCode":["297"],"capital":"Oranjestad","altSpellings":["AW"],"region":"Americas","subregion":"Caribbean","languages":{"nld":"Dutch","pap":"Papiamento"},"translations":{"deu":{"official":"Aruba","common":"Aruba"},"fra":{"official":"Aruba","common":"Aruba"},"hrv":{"official":"Aruba","common":"Aruba"},"ita":{"official":"Aruba","common":"Aruba"},"jpn":{"official":"アルバ","common":"アルバ"},"nld":{"official":"Aruba","common":"Aruba"},"por":{"official":"Aruba","common":"Aruba"},"rus":{"official":"Аруба","common":"Аруба"},"spa":{"official":"Aruba","common":"Aruba"},"fin":{"official":"Aruba","common":"Aruba"},"zho":{"official":"阿鲁巴","common":"阿鲁巴"}},"latlng":[12.5,-69.96666666],"demonym":"Aruban","landlocked":false,"borders":[],"area":180}],"message":"OK"}
findByCCN3(ccn3)
Returns a 200 Success where:
statusCode
- 200error
- falsemessage
- optional message.data
- optional payload.
Countries.findByCCN3(533);
Generates the same response as: findByCountryCode(countryCode)
findByCCA3(cca3)
Returns a 200 Success where:
statusCode
- 200error
- falsemessage
- optional message.data
- optional payload.
Countries.findByCCA3('ABW');
Generates the same response as: findByCountryCode(countryCode)
findByCIOC(cioc)
Returns a 200 Success where:
statusCode
- 200error
- falsemessage
- optional message.data
- optional payload.
Countries.findByCIOC('ARU');
Generates the same response as: findByCountryCode(countryCode)
findByCapital(capital)
Returns a 200 Success where:
statusCode
- 200error
- falsemessage
- optional message.data
- optional payload.
Countries.findByCapital('Oranjestad');
Generates the same response as: findByCountryCode(countryCode)
findBySubRegion(subRegion)
Returns a 200 Success where:
statusCode
- 200error
- falsemessage
- optional message.data
- optional payload.
Countries.findBySubRegion('Caribbean');
Generates the same response as (May have multiple entries): findByCountryCode(countryCode)
findByRegion(region)
Returns a 200 Success where:
statusCode
- 200error
- falsemessage
- optional message.data
- optional payload.
Countries.findByRegion('Americas');
Generates the same response as (May have multiple entries): findByCountryCode(countryCode)
findByResidentName(name)
Returns a 200 Success where:
statusCode
- 200error
- falsemessage
- optional message.data
- optional payload.
Countries.findByResidentName('Aruban');
Generates the same response as (May have multiple entries): findByCountryCode(countryCode)
findByLandLock(boolean)
Returns a 200 Success where:
statusCode
- 200error
- falsemessage
- optional message.data
- optional payload.
Countries.findByLandLock(false);
Generates the same response as (May have multiple entries): findByCountryCode(countryCode)
findByArea(area)
Returns a 200 Success where:
statusCode
- 200error
- falsemessage
- optional message.data
- optional payload.
Countries.findByArea(180);
Generates the same response as (May have multiple entries): findByCountryCode(countryCode)
findByCurrency(currency)
Returns a 200 Success where:
statusCode
- 200error
- falsemessage
- optional message.data
- optional payload.
Countries.findByCurrency("AWG");
Generates the same response as (May have multiple entries): findByCountryCode(countryCode)
findByCallingCode(code)
Returns a 200 Success where:
statusCode
- 200error
- falsemessage
- optional message.data
- optional payload.
Countries.findByCallingCode("297");
Generates the same response as (May have multiple entries): findByCountryCode(countryCode)
findBySpellings(spells)
Returns a 200 Success where:
statusCode
- 200error
- falsemessage
- optional message.data
- optional payload.
Countries.findBySpellings("ZW", "Republic of Zimbabwe");
Countries.findBySpellings("ZW");
Generates the same response as (May have multiple entries): findByCountryCode(countryCode)
findByBorders(borders)
Returns a 200 Success where:
statusCode
- 200error
- falsemessage
- optional message.data
- optional payload.
Countries.findByBorders("AGO", "BWA",);
Countries.findByBorders("AGO");
Generates the same response as (May have multiple entries): findByCountryCode(countryCode)
findByLat(latitude)
Returns a 200 Success where:
statusCode
- 200error
- falsemessage
- optional message.data
- optional payload.
Countries.findByLat(12);
Generates the same response as : findByCountryCode(countryCode)
findByLong(longitude)
Returns a 200 Success where:
statusCode
- 200error
- falsemessage
- optional message.data
- optional payload.
Countries.findByLong(-69.96666666);
Generates the same response as : findByCountryCode(countryCode)
findByLatLong(array)
Returns a 200 Success where:
statusCode
- 200error
- falsemessage
- optional message.data
- optional payload.
Countries.findByLatLong([12.5, -69.96666666]);
Generates the same response as : findByCountryCode(countryCode)
findByName(name)
Returns a 200 Success where:
statusCode
- 200error
- falsemessage
- optional message.data
- optional payload.
Countries.findByName('Aruba');
Generates the same response as : findByCountryCode(countryCode)
findByOfficialName(officialName)
Returns a 200 Success where:
statusCode
- 200error
- falsemessage
- optional message.data
- optional payload.
Countries.findByOfficialName('Aruba');
Generates the same response as : findByCountryCode(countryCode)
findByLanguage(name)
Returns a 200 Success where:
statusCode
- 200error
- falsemessage
- optional message.data
- optional payload.
Countries.findByLanguage('Dutch');
Generates the same response as : findByCountryCode(countryCode)
findAll()
Returns a 200 Success where:
statusCode
- 200error
- falsemessage
- optional message.data
- optional payload.
Countries.findAll();
Generates the same response as (Whole Country data): findByCountryCode(countryCode)
findById(id)
Returns a 200 Success where:
statusCode
- 200error
- falsemessage
- optional message.data
- optional payload.
Countries.findById(1);
Generates the same response as : findByCountryCode(countryCode)