Skip to content
This repository has been archived by the owner on Jun 12, 2021. It is now read-only.

Latest commit

 

History

History
90 lines (65 loc) · 1.62 KB

EXAMPLES.md

File metadata and controls

90 lines (65 loc) · 1.62 KB

Examples

  • Import module.

    • ES5
    const nba = require('nba.js').default;
    
    // OR
    
    const data = require('nba.js').data;
    const stats = require('nba.js').stats;
    • ES2015
    import nba from 'nba.js';
    
    // OR
    
    import { data, stats } from 'nba.js';
  • Each method responds with both a Promise and an error-first callback (if provided). Use whichever you prefer.

  • The following snippets will demonstrate how you can use the two APIs with their various endpoints and parameters.

  • List of methods.

  • Get a list of all players:

    nba.stats.allPlayers(function(err, res) {
      if (err) {
        console.error(err);
        return;
      }
    
      console.log(res);
    });
    nba.stats.allPlayers({ IsOnlyCurrentSeason: 0 })
      .then(res => console.log(res))
      .catch(err => console.error(err));
    nba.stats.allPlayers({ Season: '2014-15' }, (err, res) => {
      if (err) {
        console.error(err);
        return;
      }
    
      console.log(res);
    });
  • List of methods.

  • Get a list of standings:

    nba.data.standings((err, res) => {
      if (err) {
        console.error(err);
        return;
      }
    
      console.log(res);
    })
    • Get a list of teams from the 2016 season:
    nba.data.teams({
      year: 2016
    }).then(function(res) {
      console.log(res);
    }).catch(function(err) {
      console.error(err);
    });