Use the Ziptastic API to retrieve city and state information from a zip code.
Install from npm:
npm install ziptastic
ziptastic(options, [callback]) ->
The library exposes the ZIP parser function directly. It returns a promise, but will also call a node-style callback if one is passed in.
var ziptastic = ;var query = zip: '10000' country: 'US';
The function expects an object with properties
country. If no country is provided, it defaults to
US. If the
options argument is a number or numeric string, the library will assume it is a zip code in the US. All of the following are equivalent to the original query:
You can construct custom instances with your own endpoint if you're running the ziptastic application on your own server. The constructor is stored on the parser function:
var ziptastic = ziptastic;
ziptastic.create returns the
parse function bound to an instance with your
endpoint. You can also get full access to the instance using:
var ziptastic = endpoint;
The library will automatically convert HTTP status codes >= 400 into errors. Catch them using promises:
The error stores the raw response object from request as
err.response for easy debugging.