Skip to content

not able to consume thezipcodes.com search api data

I am new in nodejs and I want to use www.thezipcodes.com /api/v1/search api to search the zip code to locatioin.

I am not able to use the location returned by the API.

const request = require('request');
request('https://thezipcodes.com/api/v1/search?zipCode=13040&countryCode=US&apiKey=<apiKey>', (err, res, body) => {
    if (err) { return console.log(err); }    
    console.log(body.location);
});

Output is

undefined

In curl it is giving the output but in nodeapi I am not able to use the location array.

Answer

You should follow the example given in docs. You are receiving JSON response in string from. Please parse the body object as JSON first and then use the result.