CoinGecko API Client for Node.js
This package, `coingecko-api`, is a Node.js wrapper for the CoinGecko API, notable for its explicit lack of external dependencies. The current stable version, 1.0.10, was published over six years ago and appears to be largely unmaintained. While the CoinGecko API itself is actively developed with frequent updates and breaking changes, this particular wrapper does not reflect those ongoing developments, including new endpoints, security updates, or changes in data structures. As such, it differentiates itself by being dependency-free but offers an outdated interface to the CoinGecko API. Newer community-driven wrappers, often with TypeScript support, have emerged to keep pace with the official API's evolution.
Common errors
-
ReferenceError: require is not defined
cause Attempting to use `require()` in an ES Module (ESM) environment without proper configuration, or trying to use `import` with a CommonJS-only package.fixEnsure your project is configured for CommonJS (`"type": "commonjs"` in `package.json` or by using `.cjs` file extensions) or use a modern CoinGecko client that supports ESM imports. -
TypeError: CoinGeckoClient.someNewMethod is not a function
cause The package is abandoned and does not support new endpoints or methods introduced in the CoinGecko API since its last update over six years ago.fixCheck the official CoinGecko API documentation for the method you are trying to call. If it's a new endpoint, this wrapper will not support it. Migrate to a more recent, actively maintained CoinGecko API client or use direct HTTP requests. -
Error fetching data from CoinGecko: 429 Too Many Requests
cause Exceeded the rate limits for the CoinGecko API (e.g., 50 requests/minute for the public API).fixIntroduce a delay between API calls, implement a robust rate-limiting strategy, or subscribe to a CoinGecko Pro API plan for higher rate limits. Note that this wrapper does not handle rate limiting internally. -
property 'market_cap_rank' of undefined / null
cause Accessing `market_cap_rank` or similar fields that have been deprecated or modified in the CoinGecko API since this wrapper's last update.fixThe official CoinGecko API has introduced `market_cap_rank_with_rehypothecated` and deprecated `trust_score`. This wrapper is unaware of these changes. Either update to a current API client or add defensive coding to handle potentially `null` or missing data for these specific fields.
Warnings
- breaking This package (v1.0.10) has not been updated in over six years and does not reflect recent breaking changes in the official CoinGecko API. Endpoints, parameters, or data structures may have diverged significantly, leading to unexpected behavior or incorrect data.
- breaking The official CoinGecko API made significant breaking changes regarding how `market_cap_rank` is handled for rehypothecated tokens and deprecated the `trust_score` field in early 2026. This wrapper will likely return `null` or outdated values for these fields as it has not been updated to reflect these changes.
- gotcha This package is CommonJS-only. Attempting to use `import CoinGecko from 'coingecko-api';` directly in an ES Module context will result in a runtime error unless a compatible CJS interop mechanism is used.
- gotcha The public CoinGecko API has rate limits (e.g., 50 calls/minute for the free tier). This wrapper does not include built-in rate limiting or retry mechanisms. Exceeding limits will result in HTTP 429 Too Many Requests errors.
Install
-
npm install coingecko-api -
yarn add coingecko-api -
pnpm add coingecko-api
Imports
- CoinGecko
import CoinGecko from 'coingecko-api';
const CoinGecko = require('coingecko-api'); - CoinGecko.ORDER
import { ORDER } from 'coingecko-api';const CoinGecko = require('coingecko-api'); const order = CoinGecko.ORDER.MARKET_CAP_DESC; - CoinGecko.STATUS_UPDATE_CATEGORY
import { STATUS_UPDATE_CATEGORY } from 'coingecko-api';const CoinGecko = require('coingecko-api'); const category = CoinGecko.STATUS_UPDATE_CATEGORY.GENERAL;
Quickstart
const CoinGecko = require('coingecko-api');
const CoinGeckoClient = new CoinGecko();
const fetchPingAndBitcoinPrice = async () => {
try {
// Ping the API to check connectivity
let pingData = await CoinGeckoClient.ping();
console.log('API Ping Status:', pingData.data.gecko_says);
// Get current price of Bitcoin in USD
let bitcoinPrice = await CoinGeckoClient.simple.price({
ids: 'bitcoin',
vs_currencies: 'usd'
});
console.log('Bitcoin Price (USD):', bitcoinPrice.data.bitcoin.usd);
// Example using a constant for ordering results
let markets = await CoinGeckoClient.coins.markets({
vs_currency: 'usd',
order: CoinGecko.ORDER.MARKET_CAP_DESC,
per_page: 5
});
console.log('Top 5 Coins by Market Cap:', markets.data.map(coin => coin.name));
} catch (error) {
console.error('Error fetching data from CoinGecko:', error.message);
}
};
fetchPingAndBitcoinPrice();