req-country

Given a request, get the country code. ISO 3166-1 alpha-2 compliant.

Usage no npm install needed!

<script type="module">
  import reqCountry from 'https://cdn.skypack.dev/req-country';
</script>

README

req-country

Last version Build Status Coverage Status Dependency status Dev Dependencies Status NPM Status

Given a request, get the country associated with it. ISO 3166-1 alpha-2 compliant.

Install

$ npm install req-country --save

Usage

const requestCountry = require('req-country')

module.exports = (req, res) => {
  const country = requestCountry(req)

  console.log({ country })
  // => { country: 'ES' }
}

You can combine it with is-european and country-vat:

const { eeaMember, euMember } = require('is-european')
const requestCountry = require('req-country')
const countryVat = require('country-vat')

module.exports = (req, res) => {
  const country = requestCountry(req)

  console.log({ eeaMember: eeaMember(country), euMember: euMember(country) })
  // => { eeaMember: true, euMember: true }

  console.log(countryVat(country))
  // => 0.21
}

License

req-country © Kiko Beats, released under the MIT License.
Authored and maintained by Kiko Beats with help from contributors.

kikobeats.com · GitHub Kiko Beats · Twitter @Kikobeats