The request library in promises

Now as I mentioned earlier, some libraries support promises while others don't. The request library does not support promises. We will make a function that wraps request, returning a promise. We'll use some functionalities from the geocode.js file from the previous chapter.

First, let's discuss a quick setup, and then we'll actually fill it out. In the playground folder, we can make a new file to store this, called promise-2.js:

We'll make a function called geocodeAddress. The geocodeAddress function will take the plain text address, and it will return a promise:

var geocodeAddress = (address) => {};

The geocodeAddress ...

Get Learning Node.js Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.