The "what?"
This is the usgs.gov earthquake catalog API wrapper for NodeJS. It provides methods for accessing the data from all available endpoints:
- application.json (request known enumerated parameter values for the interface)
- application.wadl (request WADL for the interface)
- catalogs (request available catalogs)
- contributors (request available contributors)
- count (to perform a count on a data request. Count uses the same parameters as the query method)
- query (to submit a data request)
- version (request full service version number)
The "why"
While working on one of my "pet" projects I was looking for the source of real-time earthquake data. Quick search on the internet brought me to the usgs.gov website which contains all the data I needed. They also provide a free API for developers to access their data.
Since my project's back-end is written in NodeJS I started looking for a wrapper package for this service. Unfortunatelly I didn't find any up-to-date and still-maintained ready solution.
Even tho I only needed a peace of USGS earthquake catalog API functionality, I decided to implement an NodeJS wrapper for all of their available endpoints and move out the code into a separate package.
The "how"
Installation
npm install --save usgs-earthquake-api
Usage
In your code:
const api = ;
/application.json
Interface parameters const parameters = await apiapplication;
Result
/application.wadl
WADL for interface const wadlData = await apiapplicationWadl
Result
/catalogs
Available catalogs const catalogs = await apicatalogs
Result
/contributors
Available contributors const contributors = await apicontributors
Result
/count
Count on data request const count = await apicount;
Result
/query
Query const earthquakes = await apiquery;
Result
/version
Service version const version = await apiversion;
Result
Supported parameters
api.count.getCount
and api.query.earthquakes
methods accept an object with following possible
properties:
property | type | default | description |
---|---|---|---|
endtime | String | present time | Limit to events on or before the specified end time (ISO8601 format) |
starttime | String | NOW - 30 days | Limit to events on or after the specified start time (ISO8601 format) |
updatedafter | String | null | Limit to events updated after the specified time (ISO8601 format) |
minlatitude | Decimal [-90,90] degrees | -90 | Limit to events with a latitude larger than the specified minimum |
minlongitude | Decimal [-360,360] degrees | -180 | Limit to events with a longitude larger than the specified minimum |
maxlatitude | [-90,90] degrees | 90 | Limit to events with a latitude smaller than the specified maximum |
maxlongitude | Decimal [-360,360] degrees | 180 | Limit to events with a longitude smaller than the specified maximum |
latitude | Decimal [-90,90] degrees | null | Specify the latitude to be used for a radius search |
longitude | Decimal [-180,180] degrees | null | Specify the longitude to be used for a radius search |
maxradius | Decimal [0, 180] degrees | 180 | Limit to events within the specified maximum number of degrees from the geographic point defined by the latitude and longitude parameters |
maxradiuskm | Decimal [0, 20001.6] km | 20001.6 | Limit to events within the specified maximum number of kilometers from the geographic point defined by the latitude and longitude parameters |
catalog | String | null | Limit to events from a specified catalog |
contributor | String | null | Limit to events contributed by a specified contributor |
eventid | String | null | Select a specific event by ID |
includeallmagnitudes | Boolean | false | Specify if all magnitudes for the event should be included |
includeallorigins | Boolean | false | Specify if all origins for the event should be included |
includearrivals | Boolean | false | Specify if phase arrivals should be included |
includedeleted | Boolean, or only |
false | Specify if deleted products and events should be included. The value only returns only deleted events. |
includesuperseded | Boolean | false | Specify if superseded products should be included. This also includes all deleted products, and is mutually exclusive to the includedeleted parameter. |
limit | Integer [1,20000] | null | Limit the results to the specified number of events |
maxdepth | Decimal [-100, 1000] | 1000 | Limit to events with depth less than the specified maximum |
maxmagnitude | Decimal | null | Limit to events with a magnitude smaller than the specified maximum |
mindepth | Decimal [-100, 1000] km | -100 | Limit to events with depth more than the specified minimum |
minmagnitude | Decimal | null | Limit to events with a magnitude larger than the specified minimum |
offset | Integer[1,∞] | 1 | Return results starting at the event count specified, starting at 1 |
orderby | String | time | Order the results. The allowed values are: time , time-asc , magnitude , magnitude-asc |
alertlevel | String | null | Limit to events with a specific PAGER alert level. The allowed values are: green , yellow , orange , red |
eventtype | String | null | Limit to events of a specific type |
maxcdi | Decimal [0,12] | null | Maximum value for Maximum Community Determined Intensity reported by DYFI |
maxgap | Decimal [0,360] degrees | null | Limit to events with no more than this azimuthal gap |
maxmmi | Decimal [0,12] | null | Maximum value for Maximum Modified Mercalli Intensity reported by ShakeMap |
maxsig | Integer | null | Limit to events with no more than this significance |
mincdi | Decimal | null | Minimum value for Maximum Community Determined Intensity reported by DYFI |
minfelt | Integer[1,∞] | null | Limit to events with this many DYFI responses |
mingap | Decimal[0,360] degrees | null | Limit to events with no less than this azimuthal gap |
minsig | Integer | null | Limit to events with no less than this significance |
producttype | String | null | Limit to events that have this type of product associated |
productcode | String | null | Return the event that is associated with the productcode; The event will be returned even if the productcode is not the preferred code for the event |
reviewstatus | String | all | Limit to events with a specific review status; The different review statuses are: automatic , reviewed |
Error handling
Wrapper automagically processes all the API request failures and re-throws an error with a descriptive message.
From documentation about the limit
parameter:
Limit the results to the specified number of events. NOTE: The service limits queries to 20000, and any that exceed this limit will generate a HTTP response code "400 Bad Request".
Example:
try const earthquakes = await apiquery catch e console
Result
Error: Bad limit value "50000". Valid values are 0 <= limit <= 20000