Skip to content

pokedex-promise V2 Guide

pokedex-promise-v2 is a popular, lightweight Node.js client wrapper for PokéAPI. It features built-in in-memory caching, automatic rate limiting fallback configurations, and support for Promises, Async/Await, and Callbacks.

This guide will walk you through installing the package, configuring the client, and fetching Pokémon data.


Follow these steps to integrate pokedex-promise-v2 into your Node.js application:

  1. Install the package Choose your preferred package manager to add pokedex-promise-v2 to your project:

    Terminal
    npm install pokedex-promise-v2
  2. Configure your project for ESM Since version 4.0.0, pokedex-promise-v2 is a pure ES Modules (ESM) package Required.

  3. Initialize the client Import the package and initialize a new Pokedex instance.

    app.js
    import Pokedex from 'pokedex-promise-v2';
    const P = new Pokedex();
  4. Run your first query Retrieve information for a Pokémon by name or ID.

    app.js
    import Pokedex from 'pokedex-promise-v2';
    const P = new Pokedex();
    const pikachu = await P.getPokemonByName("pikachu");
    console.log(`Pokedex ID: ${pikachu.id}`);
    console.log(`Base Experience: ${pikachu.base_experience}`);
    console.log(`Primary Type: ${pikachu.types[0].type.name}`);

    Run the file with Node:

    Pokedex ID: 25
    Base Experience: 112
    Primary Type: electric

pokedex-promise-v2 is highly flexible. You can query endpoints using Async/Await, Promises, or traditional Callbacks. You can also fetch single records or retrieve arrays of records in a single call.

  • getPokemonByName(nameOrId): Fetch complete Pokémon data (stats, abilities, types, sprites) by name string (e.g. 'pikachu') or integer ID (e.g. 25).
  • getPokemonSpeciesByName(nameOrId): Fetch species-level data (flavor text descriptions, evolution chain URLs, multilingual name translations, generation info).
async-await.js
import Pokedex from 'pokedex-promise-v2';
const P = new Pokedex();
try {
const species = await P.getPokemonSpeciesByName("golduck");
const frenchName = species.names.find(n => n.language.name === 'fr').name;
console.log(`French name of Golduck: ${frenchName}`);
} catch (error) {
console.error("Failed to fetch Pokémon species data:", error);
}
French name of Golduck: Akwakwak

Root resource list endpoints (such as getPokemonsList, getBerriesList, and getItemsList) accept an optional interval object to paginate through results using limit and offset:

pagination.js
import Pokedex from 'pokedex-promise-v2';
const P = new Pokedex();
const interval = {
limit: 5, // Number of items to retrieve
offset: 33, // Starting index (0-indexed)
};
const pokemonList = await P.getPokemonsList(interval);
console.log(`Total Pokemon: ${pokemonList.count}`);
console.log(`Results:`);
pokemonList.results.forEach((pokemon) => {
console.log(` - ${pokemon.name} (${pokemon.url})`);
});
Total Pokemon: 1302
Results:
- nidoking (https://pokeapi.co/api/v2/pokemon/34/)
- clefairy (https://pokeapi.co/api/v2/pokemon/35/)
- clefable (https://pokeapi.co/api/v2/pokemon/36/)
- vulpix (https://pokeapi.co/api/v2/pokemon/37/)
- ninetales (https://pokeapi.co/api/v2/pokemon/38/)

Always specify limit and offset

By default, if you call list endpoints without passing an interval object, pokedex-promise-v2 attempts to fetch every single item in the database and cache the entire dataset into your application’s RAM. Always provide an explicit { limit, offset } when querying large resource collections!


pokedex-promise-v2 ships with built-in TypeScript type definitions out of the box no separate @types/* package is required.

When working in TypeScript, method responses are fully typed according to the official PokéAPI schemas:

example.ts
import Pokedex from 'pokedex-promise-v2';
const P = new Pokedex();
// Return values are fully typed
const pokemon = await P.getPokemonByName('pikachu');
console.log(pokemon.name); // string
console.log(pokemon.weight); // number
// Access specific return types using TypeScript utility types
type PokemonData = Awaited<ReturnType<Pokedex['getPokemonByName']>>;
function logPokemonAbilities(data: PokemonData) {
for (const item of data.abilities) {
console.log(`Ability: ${item.ability.name} (Hidden: ${item.is_hidden})`);
}
}
logPokemonAbilities(pokemon);
pikachu (Weight: 60)
Ability: static (Hidden: false)
Ability: lightning-rod (Hidden: true)

By default, the client is initialized to target the public API endpoint (https://pokeapi.co/api/v2/), timeout after 20 seconds, and cache responses in memory for 11 days.

You can customize this behavior by passing a configuration object to the constructor:

config.js
import Pokedex from 'pokedex-promise-v2';
const customOptions = {
protocol: 'https',
hostName: 'pokeapi.co',
versionPath: '/api/v2/',
cacheLimit: 5 * 60 * 1000, // Cache for 5 minutes (in milliseconds)
timeout: 5000 // Timeout after 5 seconds (in milliseconds)
};
const P = new Pokedex(customOptions);