pepega
pepega

Reputation: 7

How to fix "TypeError: Cannot read property 'then' of undefined" in nodeJS

What am I trying to do, is connect my app to third party API through node module.

You can see the code I am using right now below. I am doing a school project and the library I am using for requesting data from API can be found here

This package isnt maintained do not use it https://www.npmjs.com/package/dota2_web_api

It should show data from that match ID.

But instead I am getting TypeError: Cannot read property 'then' of undefined

What am I doing wrong with handling promise?

const bodyParser = require('body-parser');
const app = express();
const mongoose = require('mongoose');
const dotaWebAPI = require('dota2-web-api');
const api = new dotaWebAPI("<redacted api token>");

  const matchId = 3574415631
  api.getMatchDetails(matchId)
  .then(data => console.log(data.result));

Upvotes: 0

Views: 173

Answers (1)

bluehipy
bluehipy

Reputation: 2294

From their docs:

dota2API.getMatchDetails('3193699040', function(res) { console.log(res); });

so rather than using the Promise syntax try the second parameter callback.

Upvotes: 1

Related Questions