Try any Node.js package right in your browser

Share this code:

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including node-coinmarketcap-extended-api with all npm packages installed. Try it out:

node-coinmarketcap-extended-api v1.4.1

Unofficial CoinMarketCap.com API augmented with website functionality

CoinMarketCap extended API

Uses a local cache to avoid re-fetching coin info too frequently.
The cache can be configured or overriden with a custom implementation.

By default, most numbers are returned as bignumber.js instances. That behavior can be deactivated with a constructor option to make the library output only plain JavaScript numbers.
This choice was made because default JavaScript numbers are represented by floats internally, and thus are imprecise. BigNumbers can be converted to plain JS numbers by calling .toNumber on them, or prefixing them with the unary operator +.

Requires Node.js v7 or superior.
This module cannot be used in browsers due to CSP restrictions.

API

Constructor:

expiry: int|{group: string: int}(default 300000 ie. 5 minutes) Time in milliseconds before a cache entry is considered stale.
Can be indicated as a number for every entry, or an object with
different durations for each group (see example).
The object keys are groups and the values the corresponding expiry time. The object should have a default key.

Instance methods:

Cache interface:

asyncget(key: string): JSONSerializable

asyncset(key: string, value: JSONSerializable): boolean

asynchas(key: string): boolean

Additional methods and properties:

asyncisStale([key: string]):boolean
Returns whether the given cache entry has expired.

asyncclear([key: string]): boolean
Delete data for an entry, or the entire store if no argument is supplied.