A Node.js wrapper for the IGDB.com Free Video Game Database API.
One of the principles behind IGDB.com is accessibility of data. We wish to share the data with anyone who wants to build cool videogame oriented websites, apps and services. This means that the information you contribute to IGDB.com can be used by other projects as well.
Thus, you are not only contributing to the value of this site but to thousands of other projects as well. We are looking forward to see what exciting game related projects you come up with. Happy coding!
More info here:
Via npm:
$ npm install igdb-api-nodeconst igdb = require('igdb-api-node').default;import igdb from 'igdb-api-node';- Pass API key directly:
const client = igdb('YOUR_API_KEY');- OR set a process environment variable:
$ IGDB_API_KEY='YOUR_API_KEY' node yourCode.js- OR set a global-scope variable:
global.IGDB_API_KEY = 'YOUR_API_KEY';
const client = igdb();All API endpoints are available as methods on the igdb-api-node client object. Each method has the following signature:
Arguments
options- An Object containing URL query parameters and values.fields- An optional Array containing a list of desired response data fields.
Example
import igdb from 'igdb-api-node';
const client = igdb('YOUR_API_KEY');
client.games({
fields: '*', // Return all fields
limit: 5, // Limit to 5 results
offset: 15 // Index offset for results
}).then(response => {
// response.body contains the parsed JSON response to this query
}).catch(error => {
throw error;
});The available endpoints are documented and available here.
The IGDB API documentation provides details on search parameters.
igdb-api-node provides handy image method for converting objects with cloudinary_id properties to full image URLs.
Arguments
imageObject- An Object with acloudinary_idproperty defining an image ID.size- An optional string defining an image size class. Permittedsizedescriptors, from smallest to largest:micro- 35x35thumb- 90x90cover_small- 90x128logo_med- 284x160cover_big- 227x320screenshot_med- 569x320screenshot_big- 889x500screenshot_huge- 1280x720- Append '_2x' to any size descriptor to recieve a Retina (DPR 2.0) quality image, e.g.
cover_small_2x.
fileType- An optional string file extension for the image format desired, e.g.jpg,png, etc.
Example
import igdb from 'igdb-api-node';
const client = igdb('YOUR_API_KEY');
client.image({
cloudinary_id: 'example-id-123'
}, 'cover_small', 'jpg'); // https://images.igdb.com/igdb/image/upload/t_cover_small/example-id-123.jpgMore image options are available in the IGDB API documentation.
igdb-api-node provides handy method for generating tag numbers when doing advanced filtering.
Arguments
category- An integer representing the tag category (game, genre, theme)id- The ID of the category entity
Example
import igdb from 'igdb-api-node';
const client = igdb('YOUR_API_KEY'),
category = 1, // Genre
id = 5; // Shooter
client.tagNumber(1, 5); // 268435461More tag number options and information are available in the IGDB API documentation.
import igdb from 'igdb-api-node';
const client = igdb('YOUR_API_KEY'),
log = response => {
console.log(response.url, JSON.stringify(response.body, null 2));
};
/*
Search for up to two Atari platforms and return their names
*/
client.platforms({
limit: 2,
search: 'Atari'
}, [
'name'
]).then(log);
/*
Search for up to five Zelda games with release dates between 1 Jan and
31 Dec 2011, sorted by release date in descending order.
*/
client.games({
filters: {
'release_dates.date-gt': '2010-12-31',
'release_dates.date-lt': '2012-01-01'
},
limit: 5,
offset: 0,
order: 'release_dates.date:desc',
search: 'zelda'
}, [
'name',
'release_dates.date',
'rating',
'hypes',
'cover'
]).then(log);
/*
Search for two specific games by their IDs
*/
client.games({
ids: [
18472,
18228
]
}, [
'name',
'cover'
]).then(log);
/*
Search for companies with 'rockstar' in their name. Return up to five
results sorted by name in descending order
*/
client.companies({
field: 'name',
limit: 5,
offset: 0,
order: 'name:desc',
search: 'rockstar'
}, [
'name',
'logo'
]).then(log);// Grab all results using scroll API
igdb(apiKey).scrollAll('/games/?fields=name&filter[genre][eq]=7&limit=50') // Pass URL
.then(response => {
// response = Array of all game objects
});