Skip to content

Instantly share code, notes, and snippets.

@nataliaconde
Created August 11, 2020 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nataliaconde/1486269165b8ee6b37a4d01b9cc7995c to your computer and use it in GitHub Desktop.
Save nataliaconde/1486269165b8ee6b37a4d01b9cc7995c to your computer and use it in GitHub Desktop.
Building the External API Cal
var request = require('request');
const apiKey = process.env.ZIPCODE_API_KEY || "hkCt1nW1wF1rppaEmoor7T9G4ta7R5wFSu8l1dokNz8y53gGZHDneWWVosbEYirC";
const zipCodeURL = 'https://www.zipcodeapi.com/rest/';
var distance = {
find: function(req, res, next) {
request(zipCodeURL + apiKey
+ '/distance.json/' + req.params.zipcode1 + '/'
+ req.params.zipcode2 + '/mile',
function (error, response, body) {
if (!error && response.statusCode == 200) {
response = JSON.parse(body);
res.send(response);
} else {
console.log(response.statusCode + response.body);
res.send({distance: -1});
}
});
}
};
module.exports = distance;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment