Dealing with varying API results

Suppose we are writing a small server-side service in Node to get the alerts for a city and produce a not-very-fashionable HTML <table> with them, supposedly to be part of some server side-produced web page. (Yes, I know you should try to avoid tables in your pages, but what I want here is a short example of HTML generation, and actual results aren't really important.) If we used the Dark Sky API (see https://darksky.net/ for more on this API and how to register with it) to get the alarms, our code would be something like this; all quite normal. Note the callback in case of an error; you'll see why in the following code:

const request = require("superagent");const getAlerts = (lat, long, callback) => { const ...

Get Mastering JavaScript Functional Programming - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.