An easy to use postcodes.io wrapper for NodeJS.
Install the package with npm:
$ npm i node-postcodes.io
const postcodes = require('node-postcodes.io')
http://postcodes.io/docs#Postcode-Lookup
// single
let result = await postcodes.lookup('PO123AA')
// batch
let result = await postcodes.lookup(['PO123AA', 'PO123AB'])
// batch (with filter)
let result = await postcodes.lookup(['PO123AA', 'PO123AB'], {
filter: 'postcode,longitude,latitude'
})
http://postcodes.io/docs#Geocode-Postcode
//
let result = await postcodes.geo(51.7923246977375, 0.629834723775309)
// with optional params
let result = await postcodes.geo(51.7923246977375, 0.629834723775309, {
limit: 10,
radius: 10,
wideSearch: false
})
//
let result = await postcodes.geo([
{
"longitude": 0.629834723775309,
"latitude": 51.7923246977375,
"radius": 1000,
"limit": 5
},{
"longitude": -2.49690382054704,
"latitude": 53.5351312861402,
"radius": 1000,
"limit": 5
}
])
// with optional params
let result = await postcodes.geo([
{
"longitude": 0.629834723775309,
"latitude": 51.7923246977375,
"radius": 1000,
"limit": 5
},{
"longitude": -2.49690382054704,
"latitude": 53.5351312861402,
"radius": 1000,
"limit": 5
}
], {
filter: 'postcode,longitude,latitude',
wideSearch: false
})
http://postcodes.io/docs#Geocode-Postcode
let result = await postcodes.random()
http://postcodes.io/docs#Postcode-Validation
let result = await postcodes.validate('PO123AA')
http://postcodes.io/docs#Nearest-Postcode
let result = await postcodes.nearest('PO123AA')
// with optional params
let result = await postcodes.nearest('PO123AA', {
radius: 1000,
limit: 5
})
http://postcodes.io/docs#Postcode-Autocomplete
let result = await postcodes.autocomplete('PO123AA')
// with optional params
let result = await postcodes.autocomplete('PO123AA', {
limit: 5
})
http://postcodes.io/docs#Postcode-Query
let result = await postcodes.query('PO123AA')
// with optional params
let result = await postcodes.query('PO123AA', {
limit: 5
})
http://postcodes.io/docs#Terminated
let result = await postcodes.terminated('PO123AA')
http://postcodes.io/docs#Show-Outcode
// lookup
let result = await postcodes.outcodes('PO33')
// nearest
let result = await postcodes.outcodes('PO3', {
limit: 10,
radius: 10
})
// nearest (lat, lng)
let result = await postcodes.outcodes(51.7923246977375, 0.629834723775309)
// with optional params
let result = await postcodes.outcodes(51.7923246977375, 0.629834723775309, {
limit: 10,
radius: 10
})
http://postcodes.io/docs#Place-Lookup
// lookup
let result = await postcodes.places('osgb4000000074553605')
// query
let result = await postcodes.places('Ryde', {
limit: 10
})
// random
let result = await postcodes.places()
Can see test results @ https://travis-ci.org/lcherone/node-postcodes.io, if you want to run them locally, your need install mocha, then run:
$ npm test
The MIT License (MIT). Please see License File for more information.