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 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 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.