River Gage Height

node v4.9.1
version: 3.0.0
endpointsharetweet
Example of using USGS river gage data to create a simple service.
var fetch = require('fetch-everywhere'); exports.endpoint = function (req, res) { fetch('https://waterservices.usgs.gov/nwis/iv/?format=json&sites=05341550,05344490&parameterCd=00060,00065&siteStatus=all') .then(function (response) { return response.json(); }) .then(function (result) { var timeSeries = result.value.timeSeries.filter(ts => ts.variable.variableName === "Gage height, ft"); res.writeHead(200, { 'content-type': 'text/plain' }); res.write("Gage,Height\n"); timeSeries.forEach(ts => { var gage = ts.sourceInfo.siteName.replace(",", ""); var height = ts.values[0].value[0].value; res.write(gage + "," + height + "\n"); }); res.end(); }) .catch(function (err) { res.writeHead(500, { 'content-type': 'text/plain' }); res.end("500 Server Error"); }); };
Loading…

no comments

    sign in to comment